Here are some quick notes on using the
Digg API
with a Python script. Note, there is a
Python
toolkit for Digg but I just used urllib2
and the Digg API endpoints for the sake of simplicity.
I wanted the output in JSON format so I specified the response type as JSON. To decode JSON directly to a Python data structure, I used simplejson.
Here is a simple example which returns the JSON output for
the Digg story
Dell
vs. Apple: This Time it's Personal
which has a "clean title" of
Dell_vs_Apple_This_Time_it_s_Personal.
#!/usr/bin/env python
import urllib2
APPKEY ...$ tar -zxvf gnip-gnip-python-028364a70bd40dda0069ecdd3e7f6fff23bb985e.tar.gz
$ mkdir ~/src/python/gnip-example $ mv gnip-gnip-python-028364a70bd40dda0069ecdd3e7f6fff23bb985e/*.py ~/src/python/gnip-example
~/src/python/gnip-example/gnip-example.py:
#!/usr/bin/env python
from gnip import *
gnip = Gnip("yourgniplogin@email.com", "yourpassword")
for publisher in ["twitter", "digg", "delicious"]:
activities = gnip.get_publisher_activities(publisher)
print
print publisher
for activity in activities[:5]:
print activity
$ python gnip-example.py
twitter [derricklo, 2008-08-01T22:49:59+00:00, tweet, http://twitter.com ...
I'm Eliot and this is my notepad for programming topics such as Python, Django, Ubuntu, Emacs, etc... more »