Python module for TwitPic album backups
Thursday, March 18, 2010 at 1:28PM This is a little something I threw together last night due to my frustration at not being able to find a decent utility for backing up my TwitPic album. It's not the most efficient code out there, and in most places it's downright hacky, but it serves its intended purpose, and maybe it'll help some other people who want to develop Python apps that can use TwitPic photos, or people who just want to back up their pictures.
I might as well warn you ahead of time that due to the nature of this program, if the TwitPic staff ever decides to redesign the site, there's a very good chance this program will be broken as a result. Since the official TwitPic API didn't offer any solutions that I could see for downloading pictures or entire albums, I wrote this script to parse the HTML in the pages and harvest the necessary information. If they change this, it will no longer work. Other than that, enjoy the script, and be sure to read the readme file below, or inside the ZIP package.
TwitPic Photo Dumper by Ryan Souders (@HonkeyKong)
http://www.honkeykong.org/
This initial release doesn't really do much, so if you're looking for a full-featured photo utility, look elsewhere. In its current state, this is mainly good for two things: backing up your TwitPic photo album, or to be used as a module in your own applications.
For the former, all you need is a Python interpreter and basic knowledge of how to use the command line in your Operating System. It should work the same under Windows, Linux, and Mac OS X, but I have only tested it under Windows and Linux. If you have a Mac, let me know how it works out for you.
In Mac OS X and most Linux distributions, Python should already be installed on your computer. Windows does not come with it though, and as such, I recommend downloading and installing ActivePython from the following URL: http://www.activestate.com/activepython/
Once you're sure you have a Python interpreter installed, you can run the script and backup your photos by opening a command line or terminal, navigating to the location where you placed the script, and executing the following command:
twitpic.py twitter_ID number_of_pages
Obviously, "twitter_ID" should be replaced with your Twitter handle, and "number_of_pages" should be replaced with the number of photo pages you want to download. Each TwitPic page holds 20 photos. Once the script has finished running, you should have a new folder with your user ID, filled with your photos, and text files containing the descriptions for each photo. It could be handled better, but this isn't intended to be a professional tool, just a means for me to back up my photos that I thought I should share, so others can do the same without wasting hours saving them individually.
Now that I have the non-developer stuff out of the way, here's what you need to know if you're a developer and for some reason want to use my crappy code to add TwitPic functionality into your own app:
twitpic.fetchList(userID, numPages)
This function will iterate through a user's photo album, up to the maximum page number specified in the numPages argument, and return all photo IDs in a list format.
twitPic.picInfo(picID)
This function retrieves the description for the photo located at the URL http://twitpic.com/picID
twitPic.fetchTitles(userID, numPages)
This function iterates through userID's photo album, up to numPages, and retrieves the description for every photo in the album, writing each one individually to a text file with that photo's ID.
twitPic.downloadPic(picID)
This function downloads the full-sized version of the photo located at http://twitpic.com/picID
twitPic.leechPics(userID, numPages)
This is the function that will download every picture and title, up to the number of pages specified in numPages. It should go without saying that this function should only be used to back up your own photographs, as using it to leech the albums of other users or to harvest large amounts of photo albums can be considered a dick move toward the TwitPic staff. Bandwidth isn't cheap, so there's no sense in using more of their bandwidth than you really need to.
I think that's all that needs to be said here. If you think I forgot something, you have a suggestion, or a question about this, feel free to e-mail me at honkeykong at honkeykong dot org, or send me a message on Twitter at http://twitter.com/HonkeyKong

