Skip to content

Instantly share code, notes, and snippets.

Created December 28, 2014 15:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Print the tweets in a Twitter archive that are younger than a year, useful for heroku_ebooks
#!/usr/bin/env python
from cStringIO import StringIO
from csv import DictReader
from sys import argv
from zipfile import ZipFile
from arrow import utcnow
import dateutil.parser
def twitter2ebooks(path):
archive = ZipFile(path)
csv ='tweets.csv')
csv = StringIO(csv)
rows = DictReader(csv)
now = utcnow()
for row in rows:
created_at = row['timestamp']
created_at = dateutil.parser.parse(created_at)
if (created_at - now).days < 365:
print repr(row['text'])
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment