Skip to content

Instantly share code, notes, and snippets.

@hugs
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hugs/fa7892da03ce660c212e to your computer and use it in GitHub Desktop.
Save hugs/fa7892da03ce660c212e to your computer and use it in GitHub Desktop.
Twitpic Image and Data Archiver
# Archive your Twitpic photos and metadata
#
# A cleaned-up fork of Terence Eden's original archiver:
# http://shkspr.mobi/blog/2013/08/exporting-twitpic-images-python/
#
# License: MIT
import urllib
import urllib2
import json
import time
import os
USERNAME = "your_username_goes_here"
NUMBER_OF_PAGES_TO_DOWNLOAD = 5
# Target Page
api = "https://api.twitpic.com/2/users/show.json?username=%s&page=" % 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))
page_file.close()
# 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 = "https://twitpic.com/show/full/"+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