Add tool to merge messages logs together for populate_db.

This tool hardcodes the paths to the input log files; we'll need to
change that down the line.

(imported from commit 8b067a6d3dc781694a001d549e5e60900d9c2596)
This commit is contained in:
Tim Abbott 2012-12-11 14:04:07 -05:00
parent c21535d420
commit b14e4d2a57
1 changed files with 21 additions and 0 deletions

21
tools/merge-messages-logs Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/python
import simplejson
items_by_timestamp = {}
def read_log_file(filename):
with open(filename, 'r') as log:
for ln in log:
m = simplejson.loads(ln)
m["timestamp"] = float(m["timestamp"])
items_by_timestamp.setdefault(m["timestamp"], [])
items_by_timestamp[m["timestamp"]].append(m)
read_log_file("all_messages_log.merged.2012-12-05")
read_log_file("all_messages_log.staging.humbughq.com")
read_log_file("all_messages_log.app.humbughq.com")
with open("all_messages_log.monastery", "w") as log:
for stamp in sorted(items_by_timestamp.keys()):
for item in items_by_timestamp[stamp]:
log.write(simplejson.dumps(item) + "\n")