Skip to content

Instantly share code, notes, and snippets.

@timcowlishaw
Created June 17, 2009 09:12
Show Gist options
  • Save timcowlishaw/131159 to your computer and use it in GitHub Desktop.
Save timcowlishaw/131159 to your computer and use it in GitHub Desktop.
SLOT_ID_REGEXP = /^\|.+\|.+\|.+\|.+\|.+\|(.+)\|.+\|/
def winner_id_regexp(slot_id)
/INSERT\ INTO\ \`winners\`\ \(\`updated_at\`\,\ \`competitor_id\`\,\ \`activation_code\`\,\ \`slot_id\`\,\ \`created_at\`\)\ VALUES\(\'.+\'\,(.+)\,\ \'.+\'\,\ #{slot_id}\,\ \'.+\'\)/
end
File.open("/Users/tim/winners-pick.log") do |log|
@log = log.read.split("\n")
end
@pairs = []
File.open("/Users/tim/new_winners.txt") do |new_winners|
new_winners.each_line do |line|
slot_id_match = SLOT_ID_REGEXP.match(line)
slot_id = slot_id_match.captures[0].strip.to_i if slot_id_match
log_line = @log.find {|l| l =~ winner_id_regexp(slot_id) } if slot_id
match = competitor_id = winner_id_regexp(slot_id).match(log_line) if log_line
competitor_id = match.captures[0].strip.to_i if match
@pairs << [slot_id, competitor_id] if competitor_id
end
end
require 'pp'
require 'rubygems'
require 'json'
puts @pairs.to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment