Created
August 3, 2011 12:36
-
-
Save eiszfuchs/1122534 to your computer and use it in GitHub Desktop.
convert tweet backup into Day One Journal entries
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
import os, glob, string | |
import datetime, calendar | |
import json, rfc822, plistlib | |
root = './backup/' | |
tweet_count = 0 | |
print 'conversion started' | |
if not os.path.exists('./entries/'): | |
os.mkdir('./entries/') | |
for folder in glob.glob(root): | |
for file in glob.glob(folder + '/*.*'): | |
file = open(file) | |
content = json.loads(file.read()) | |
try: | |
content['retweeted_status'] | |
except KeyError: | |
# is no retweet | |
text = content['text'] | |
if text[0] != '@': | |
# clean the t.co mess | |
try: | |
content['entities'] | |
except KeyError: | |
print 'no entities, old tweet?' | |
else: | |
for url in content['entities']['urls']: | |
if url['expanded_url'] != None: | |
print url['url'], '-->', url['expanded_url'] | |
text = string.replace(text, url['url'], url['expanded_url']) | |
status_id = content['id'] | |
uuid = 'twitter' + str(status_id) | |
created_at = calendar.timegm(rfc822.parsedate(content['created_at'])) | |
created_at = datetime.datetime.fromtimestamp(created_at) | |
# this is pretty neat: | |
data = { | |
"Creation Date": created_at, # it automatically converts the timestamp | |
"Entry Text": text, | |
"Starred": False, | |
"UUID": uuid | |
} | |
plistlib.writePlist(data, './entries/'+uuid+'.doentry') #boom! | |
tweet_count += 1 | |
print 'done, converted ' + str(tweet_count) + ' tweets' |
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
{"favorited":false,"in_reply_to_status_id_str":null,"entities":{"urls":[{"indices":[9,28],"display_url":"samspratt.tumblr.com\/post\/647990304\u2026","url":"http:\/\/t.co\/ksAqa9W","expanded_url":"http:\/\/samspratt.tumblr.com\/post\/6479903042\/troll-face-evolved-by-sam-spratt-i-was"}],"user_mentions":[],"hashtags":[]},"user":{"default_profile":false,"profile_sidebar_fill_color":"8597a6","protected":false,"contributors_enabled":false,"lang":"de","statuses_count":6758,"profile_background_tile":true,"profile_image_url":"http:\/\/a3.twimg.com\/profile_images\/1295992705\/eiszfuchs.twitter.mark2_normal.png","name":"ei\u017f\u0292fuchs","listed_count":7,"verified":false,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/181458768\/noise.png","utc_offset":3600,"profile_link_color":"1a527f","followers_count":103,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1295992705\/eiszfuchs.twitter.mark2_normal.png","screen_name":"eiszfuchs","profile_sidebar_border_color":"dddddd","location":"Europe \u203a Germany \u203a NRW \u203a K\u00f6ln","time_zone":"Berlin","friends_count":149,"default_profile_image":false,"following":true,"profile_use_background_image":true,"url":"http:\/\/eisfuchslabor.de\/","description":"Ein kleiner Fuchs in einer gro\u00dfen Stadt, der gerne Spiele spielt, Programme programmiert und Bilder bildet.","profile_background_color":"f2f2f2","id_str":"14797650","is_translator":false,"profile_background_image_url":"http:\/\/a1.twimg.com\/profile_background_images\/181458768\/noise.png","created_at":"Fri May 16 11:29:36 +0000 2008","show_all_inline_media":true,"follow_request_sent":false,"geo_enabled":true,"notifications":false,"id":14797650,"favourites_count":497,"profile_text_color":"0f2c44"},"place":null,"in_reply_to_screen_name":null,"in_reply_to_user_id_str":null,"contributors":null,"geo":null,"retweeted":false,"truncated":false,"coordinates":null,"text":"Problem? http:\/\/t.co\/ksAqa9W","in_reply_to_user_id":null,"retweet_count":0,"in_reply_to_status_id":null,"id_str":"98690979980247040","source":"web","created_at":"Wed Aug 03 09:45:37 +0000 2011","possibly_sensitive":false,"id":98690979980247040} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Creation Date</key> | |
<date>2011-08-03T11:45:37Z</date> | |
<key>Entry Text</key> | |
<string>Problem? http://samspratt.tumblr.com/post/6479903042/troll-face-evolved-by-sam-spratt-i-was</string> | |
<key>Starred</key> | |
<false/> | |
<key>UUID</key> | |
<string>twitter98690979980247040</string> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment