本文整理汇总了Python中tumblr.Api.write_photo方法的典型用法代码示例。如果您正苦于以下问题:Python Api.write_photo方法的具体用法?Python Api.write_photo怎么用?Python Api.write_photo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tumblr.Api
的用法示例。
在下文中一共展示了Api.write_photo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWrite
# 需要导入模块: from tumblr import Api [as 别名]
# 或者: from tumblr.Api import write_photo [as 别名]
def testWrite(self):
api = Api(BLOG, USER, PASSWORD)
newpost = api.write_regular('title','body')
post = api.read(newpost['id'])
assert newpost['id'] == post['id']
newpost = api.write_link('http://www.google.com')
post = api.read(newpost['id'])
assert newpost['id'] == post['id']
newpost = api.write_quote('it was the best of times...')
post = api.read(newpost['id'])
assert newpost['id'] == post['id']
newpost = api.write_conversation('me: wow\nyou: double wow!')
post = api.read(newpost['id'])
assert newpost['id'] == post['id']
newpost = api.write_video('http://www.youtube.com/watch?v=60og9gwKh1o')
post = api.read(newpost['id'])
assert newpost['id'] == post['id']
newpost = api.write_photo('http://www.google.com/intl/en_ALL/images/logo.gif')
post = api.read(newpost['id'])
assert newpost['id'] == post['id']
示例2: main
# 需要导入模块: from tumblr import Api [as 别名]
# 或者: from tumblr.Api import write_photo [as 别名]
def main():
if len(sys.argv) != 2:
print "Usage: ./totumblr.py <photofile>"
sys.exit(-1)
photo_filename = sys.argv[1]
parts = photo_filename.split('.')
file_extension = parts[1]
ftp = FTP('www.fakemachine.com')
ftp.login('[email protected]','password')
ftp.cwd('/domains/fakemachine.com/html/tumblrimages/')
text = ftp.retrlines('list')
m = re.search('\d+ matches', text)
match = m.group(0)
parts = match.split(' ')
file_number = int(parts[0]) + 1
remote_filename = "%d.%s" % (file_number,file_extension)
fp = open(photo_filename,'rb')
ftp.storbinary('STOR %s' % remote_filename, fp) # Send the file
fp.close()
ftp.quit()
image_url = "http://www.fakemachine.com/tumblrimages/%s" % remote_filename
api = Api(BLOG,USER,PASSWORD)
post = api.write_photo(source=image_url)
print "Published: ", post['url']