Created
July 5, 2012 21:20
-
-
Save jgmarcel/3056557 to your computer and use it in GitHub Desktop.
Modified version of Dr. Drang's ThinkUp db -> text file script. Adds timestamp conversion from UTC to local time.
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 csv | |
import os | |
import time | |
import calendar | |
import sys | |
# Put your Twitter username here. | |
me = "drdrang" | |
# Archive format. | |
single = "%s\n%s\nhttp://twitter.com/" + me + "/status/%s" | |
# Open the CSV file specified on the command line and read the field names. | |
tfile = open(sys.argv[1]) | |
treader = csv.reader(tfile) | |
fields = treader.next() | |
# Fill a list with the tweets, with each tweet a dictionary. | |
allInfo = [] | |
for row in treader: | |
allInfo.append(dict(zip(fields,row))) | |
# Collect only the info we need in a list of lists. Convert the date string | |
# into a datetime object. | |
tweets = [ [time.localtime(calendar.timegm(time.strptime(x['pub_date'], "%Y-%m-%d %H:%M:%S"))), \ | |
x['post_id'], x['post_text']] \ | |
for x in allInfo ] | |
# We put the date first so we can sort by date easily. | |
tweets.sort() | |
# Construct a new list of tweets formatted the way the IFTTT recipe does. | |
out = [ single % \ | |
(x[2], time.strftime("%B %d, %Y at %I:%M%p", x[0]), x[1]) \ | |
for x in tweets ] | |
print '\n- - - - -\n\n'.join(out) | |
print '\n- - - - -' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Diff output: