|
Project Information
Members
|
Python wrapper for the Tumblr API Usage
ReadingPosts can be accessed via an iterator that takes care of all the details of paging through results sets. Here is an example that builds a frequency dictionary then charts it with Google Charts.
from tumblr import Api
from pygooglechart import PieChart3D
chart = PieChart3D(400, 200)
api = Api('staff.tumblr.com')
freq = {}
posts = api.read()
for post in posts:
type = post['type']
try:
freq[type] += 1
except:
freq[type] = 1
chart.add_data(freq.values())
chart.set_pie_labels(freq.keys())
chart.set_title('staff.tumblr.com')
chart.download('staff.png')
WritingSupported post types have a write method defined for them. Here is an example of a simple CLI app to publish a regular post from the command line: $ python tumbl.py "Title of post" "Body of Post" Published: http://YOU.tumblr.com/post/36632808 from tumblr import Api import sys BLOG='YOU.tumblr.com' USER='YOUREMAIL' PASSWORD='YOURPASSWORD' if len(sys.argv) != 3: print "Usage: tumbl <title> <body>" sys.exit(-1) title = sys.argv[1] body = sys.argv[2] api = Api(BLOG,USER,PASSWORD) post = api.write_regular(title,body) print "Published: ", post['url'] ImportingIf porting to tumblr from an existing blog, python-tumblr can be used to bring over existing content ( this is what I did with AsciiArmor. Below is an example that pulls a weather feed via RSS and posts it to your tumblr account. If bringing historical content, the date would need to be specified on the write_regular call.
from tumblr import Api
import feedparser
BLOG='YOU.tumblr.com'
USER='YOUREMAIL'
PASSWORD='YOURPASSWORD'
api = Api(BLOG,USER,PASSWORD)
d = feedparser.parse('http://feeds.weatherbug.com/rss.aspx?zipcode=27702&feed=curr&zcode=z4641')
for e in d.entries:
api.write_regular(e.title,e.summary)
|
