Created
June 12, 2014 23:50
-
-
Save meyarivan/e3d0a8c07c76fade0fd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import sys | |
from datetime import date, timedelta, datetime | |
import simplejson as json | |
def parse(filex): | |
data = json.loads(filex.read(), 'utf8') | |
activity_summary = {} | |
for d in data: | |
dt = datetime.strptime(d["datetime"], '%Y-%m-%dT%H:%M:%S').strftime('%Y-%m-%d') | |
act_tag = '%s_%s' % (dt, d["extra"]["type"]) | |
# check whether we have users for that activity | |
if (act_tag in activity_summary): | |
users = activity_summary[act_tag] | |
else: | |
activity_summary[act_tag] = users = {} | |
users[d['email']] = users.setdefault(d['email'], 0) + 1 | |
return activity_summary | |
if __name__ == '__main__': | |
activity = parse(sys.stdin) | |
for act_tag in activity: | |
for user in activity[act_tag]: | |
dt = act_tag.split("_")[0] | |
cnt = activity[act_tag][user] | |
print '%s,%s,%s' % (dt, user, cnt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment