PythonでTumblrに画像を投稿するテスト
tumblr.py
#! /usr/bin/env python # coding: utf-8 import urllib TUMBLR_URL = 'http://www.tumblr.com/api/write' def postImg(url, caption='', link=''): pd = {} pd['email'] = 'mailaddress' pd['password'] = 'password' pd['group'] = 'progdhoge.tumblr.com' pd['type'] = 'photo' pd['source'] = url pd['caption'] = caption pd['click-through-url'] = link params = urllib.urlencode(pd) up = urllib.urlopen(TUMBLR_URL, params) print up.read()
terminalで
$ python Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import tumblr >>> tumblr.postImg("http://www.hatena.ne.jp/users/pr/progd/user.jpg?1236178259", "test") 168619255 >>>