Python-TwitPic v2.0

Monday, 01 November 2010

Last week I updated Python-TwiPic to API v2.0. TwitPic announced that they will continue supporting the old version, however, I recommend upgrading to the latest and greatest. Version 2.0 addresses some security concerns and comes with tons more functionality than the previous.

A while back Twitter introduced an extension to oAuth called Echo oAuth. In short, it's a way to provide a Twitter access_token to the media provider (TwitPic) instead of providing a username and password. As you may already know, TwitPic introduced more than photo uploading to their API. Now you can leave comments group and assign photos to events, and tag faces in a photo. I personally am only using TwitPic to upload photos but the extra features could be nice depending on your intentions.

The only request methods that TwitPic currently accepts are GET and POST. In this library, I chose to break up the method request calls into the four main RESTful request groups GET, PUT, POST, DELETE. Each request method belongs to a RESTful request group depending on it's function. Below is an example use case. You must first choose the appropriate method which is either: read, create, update, or remove. Then you pass a method the method call name and a dictionary of parameters (not including a service key). Seems pretty straightforward I hope. Also keep in mind that you are responsible for getting a user's access_token and should be passed as a string which I believe is fairly standard practice.

Usage:

1
2
3
4
5
6
7
8
9
import twitpic2
twitpic = twitpic2.TwitPicOAuthClient(
    consumer_key = CONSUMER_KEY,
    consumer_secret = CONSUMER_SECRET,
    access_token = ACCESS_TOKEN,
    service_key = SERVICE_KEY
)
# methods - read, create, update, remove    
response = twitpic.create(METHOD_CALL, PARAMS)

If you find any bugs please create a ticket so that I can fix them.

Leave a comment

Django-VideoThumbs

Sunday, 03 January 2010

I have been in need of a video thumbnailer for some time now and so I decided to create a proof of concept django model field that does just that. Note that since this is just a proof of concept project, I don't recommend using this in a production settings. This project is based heavily on the django-thumbs project but for videos instead. In order to create thumbnails for videos we must first extract a frame.

Extracting a frame can be done by using FFMpeg. The main problem is that the python FFMpeg libraries that currently exist are broken and have been for some time now. pyFFMpeg is getting a rewrite but it appears that it won't be ready anytime soon. As a quick hack, I simply pipe out to the command line and extract a group of frames. From there I find which frame has the most color and proceed with thumbnailing that frame. In case you were wondering, some videos contain black frames at the begin of the movie so instead of taking the very first frame, I take a sample of frames and find the frame with the most color.

For obvious reasons, this is NOT the best solution. In the future, if/when I get the time I plan on experimenting with ctypes since its a standard library that ships with python 2.5+. If you have any questions or would like to help please contact me.

Here is the Project Location.

Leave a comment

Python TwitPic

Thursday, 29 January 2009

Today I created a dead simple python lib called python-TwitPic. It makes use of the extremely simple API that http://twitpic.com/ has to offer offer.

Check out the code here:

http://code.google.com/p/python-twitpic/

Usage:

1
2
3
4
5
import twitpic
twit = twitpic.TwitPicAPI('USERNAME', 'PASSWORD')
twitpic_url = twit.upload('FILE_LOCATION')
# twitpic_url = twit.upload('FILE_LOCATION', message='messages rock!')
print twitpic_url

Enjoy!

Leave a comment