Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Twitpic Image and Data Archiver
# Archive your Twitpic photos and metadata
# A cleaned-up fork of Terence Eden's original archiver:
# License: MIT
import urllib
import urllib2
import json
import time
import os
USERNAME = "your_username_goes_here"
# Target Page
api = "" % USERNAME
# Get the data about the target page
for page in range(1, NUMBER_OF_PAGES_TO_DOWNLOAD+1):
print page
raw_data = urllib2.urlopen(api + str(page))
json_data = json.load(raw_data)
# Save the page data
page_file = open("page-%s.json" % page,"w")
page_file.write(json.dumps(json_data, indent=2))
# Get the info about each image on the page
images = json_data["images"]
for item in images:
file_id = item["short_id"]
file_type = item["type"]
file_time = time.mktime(time.strptime(item["timestamp"], "%Y-%m-%d %H:%M:%S"))
file_url = ""+file_id
file_name = file_id + "." + file_type
# Save the file
urllib.urlretrieve (file_url, file_name)
# Set the file time
os.utime(file_name,(file_time, file_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.