Add image to Tumblr using Python

I am trying to post a picture in tumblr using python in particular: http://code.google.com/p/python-tumblr/

#! / Usr / bin / python

from tumblr import Api
import sys

BLOG='example.tumblr.com'
USER='example@example.com'
PASSWORD='example'
api = Api(BLOG,USER,PASSWORD)
post_data = "picture.png"   
title = "Title of my entry"
body = "this is a story with a picture"

api.write_regular(title, body + post_data)

When I run this, the result is that a blog comes in, but instead:

Title of my post

This is a story depicting

[IMG]

I get this:

Title of my post

this is a story with picturepicture.png

+3
source share
3 answers

In your current code, you are not placing an image, but you are sending a line called "picture.png". As Daniel Di Paolo said, you need to write a photo. The argument for write_photo is a link to an image, for example.

#!/usr/bin/python
from tumblr import Api
import sys

BLOG='example.tumblr.com'
USER='example@example.com'
PASSWORD='example'
api = Api(BLOG,USER,PASSWORD)
api.write_photo('http://example.org/somewhere/lolcat.jpg')

If you want to send HTML, you can create a body that long contains the tags of your options.

title = "life is amazing" 
body = """
_here my html code_
"""

API

api.write_regular(title,body)

.

;) , , . , "lolcat.jpg"

data = open ('lolcat.jpg'). read()

+2

, , . write_regular HTML, , -, <img src="..." /> .

write_photo ( !) Tumblr, - URL- <img> .

+2

I made an example here, with API v2 https://gist.github.com/1242662

+1
source

Source: https://habr.com/ru/post/1790812/


All Articles