Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@brendano
Created October 27, 2014 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendano/1380f006c233c5901514 to your computer and use it in GitHub Desktop.
Save brendano/1380f006c233c5901514 to your computer and use it in GitHub Desktop.
tw2created_at_iso.py
#!/usr/bin/env python
import ujson as json
import time,sys
from datetime import datetime
def parse_date(twitter_lame_datetime_string):
# e.g. the 'created_at' field
ts = time.strptime(twitter_lame_datetime_string, "%a %b %d %H:%M:%S +0000 %Y")
return datetime(*ts[:7])
for line in sys.stdin:
tw = line.split('\t')[-1]
tw = json.loads(tw)
d = parse_date(tw['created_at'])
created_at_iso = d.strftime("%Y-%m-%dT%H:%M:%S")
print "%s\t%s" % (created_at_iso, line.rstrip('\n'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment