Skip to content

Python script to generate tumblr posts

Hello Community,

I've created a small Python script which allows you to create relevant posts on (expired) tumblr blogs.

It is using the OpenAI, pytumblr2 (https://pypi.org/project/PyTumblr2/), and csv Python libraries.

Prerequisites:

  • OpenAI API access
  • Tumblr API access
  • Python
  • Installation of the Python libraries
pip install openai<br>pip install csv<br>pip install pytumblr2
A local text file 'urls.txt' with the URLs of which you want to create and publish tumblr posts for. Format:
<div>URL</div><div><b>https://URL1</b></div><div><b>https://URL2</b></div><div><b>https://URL3
...</b></div>
Code:
<div>import csv</div><div>import pytumblr2</div><div>from openai import OpenAI</div><div><br></div><div>#OpenAI authentification</div><div>openaiclient = OpenAI(</div><div>&nbsp; &nbsp; api_key='<b>YOUR OPENAI API KEY'</b>,</div><div>&nbsp; &nbsp; )</div><div><br></div><div># tumblr authentification</div><div>tumblrclient = pytumblr2.TumblrRestClient(</div><div>&nbsp; <b>YOUR TUMBLR API ACCESS DATA (SEE API DOCUMENTATION)
</b></div><div>)</div><div><br></div><div>#tumblr Blog</div><div>tumblrblog = "<b>NAME OF YOUR TUMBLR BLOG TO BE USED</b>"</div><div><br></div><div>#Read URLs from file and start processing</div><div>with open('urls.txt') as csv_file:</div><div>&nbsp; &nbsp; csv_reader = csv.reader(csv_file, delimiter=',')</div><div>&nbsp; &nbsp; line_count = 0</div><div>&nbsp; &nbsp; for row in csv_reader:</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if line_count == 0:</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f'Column names are {", ".join(row)}')</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line_count += 1</div><div>&nbsp; &nbsp; &nbsp; &nbsp; else:</div><div>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f'\t{row[0]}')</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f'{row[0]}')</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url = (f'{row[0]}')</div><div><br></div><div>#Create tumblr content</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; openaicontentprompt = "Create a tumblr post for this blog: " + url</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response = openaiclient.completions.create(</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model="gpt-3.5-turbo-instruct",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prompt = openaicontentprompt,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; max_tokens = 1000,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temperature = 0.7</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tumblrpost = (response.choices[0].text)</div><div><br></div><div>#Create tumblr title</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; openaititleprompt = "Create a title for this tumblr post: \n" + tumblrpost</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response = openaiclient.completions.create(</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model="gpt-3.5-turbo-instruct",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prompt = openaititleprompt,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; max_tokens = 100,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temperature = 0.7</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="background-color: transparent; color: inherit; font-size: inherit; font-family: "Open Sans", HelveticaNeue-Light, "Segoe UI", "Helvetica Neue", Helvetica, Raleway, Arial, sans-serif;">tumblrtitle = response.choices[0].text.replace('"', '')</span></div><div><br></div><div># Publish post on tumblr</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(tumblrclient.info())</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tumblrclient.create_post(tumblrblog, content=[{"type": "text","subtype": "heading1","text": tumblrtitle},{"type": "text","text": tumblrpost},{"type": "link","url": url}])</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line_count += 1</div><div>&nbsp; &nbsp; print(f'Processed {line_count} lines.')</div>

Once done, boost your tumblr blog with GSA SER links.

The links built on tumblr are direct links, dofollow, no redirects.

The script is not using a browser emulation like Selenium, thus independent from changes on the web frontend.

Feel free to use, modify or even attempt to become billionaire overnight by attempting to sell the code on BHW.

There are various opportunities for improvement like embedding images, formatting the tags, etc.. Feel free to do so on your own.

I am open to suggestions but WILL NOT provide any troubleshooting nor find expired tumblr blogs for you. Read the API documentations. Read the manuals on how to find expired tumblrs.

Comments

  • Great to see some contributing ! ! !

    Posting via API's when provided is def faster and more reliable then scripts depending on frontend,  no question there!

    Plus, its harder to get bans since its "your" verified blogs and "they" provide the API.

    I consistently find expired tumblrs over Moz rank 3 with unspammed decent metrics and backlink profiles. 

    I've found its helpful traffic wise to add tags even manually to the main account topically related to posts your publishing on your blogs.

    You can do this in Tumblr same as Main Youtube channel tags not just for individual posts. (not sure is some are aware of this)

    This will give your blog more chance to be "seen" and send real referal traffic to your site if quality related content was posted which should greatly affect your overall core web vitals since your get traffic coming in from  trusted high authority sites.

    Which inturn helps overall SEO strategy.(depending on goals of coarse)

    This interests me as im doing/testing something very similar.

    I didnt try or completely understand so following is my assumption. . . 

    You have provided Python client libararies and a script that will post to Tumblr Via API using content via OpenAI API using URLS you provide in a text file?

    It then creates a "title" and "blog post" from that URL by prompting OpenAI and then posts to Tumblr?

    Is that basically correct?

    I have many code snippets for example, that will add tag press enter, add tag press enter etc but they are in javascript.

    I wonder if it would be easy to add more variables in files like posttags.txt and channeltags.txt and pull or prompt from there or even images from Dall-E as you suggestted for improvement?

    This could be interesting as well as potentially ruin a business idea I had  :wink:

















  • Great to see some contributing ! ! !

    You have provided Python client libararies and a script that will post to Tumblr Via API using content via OpenAI API using URLS you provide in a text file?

    It then creates a "title" and "blog post" from that URL by prompting OpenAI and then posts to Tumblr?

    This could be interesting as well as potentially ruin a business idea I had

    Thanks for your feedback.

    The Python libraries are not mine. These are the official libraries maintained by the Python gurus, OpenAI and tumblr.

    All I did was to use the libraries in a small script.

    This script basically "reads" the content of a given URL (urls.txt) and instructs OpenAI to generate a tumblr-post with a decent title on it. tumblr is a different platform than i.e. Wordpress, different user group and thus different post format than pure article content. Short, captivating, easy to share. From the results I have seen, OpenAI is doing a very decent job creating these posts, even with tags included (not extracted seperately in this version of my script).

    There are many opportunities to enhance it. Be it (DALL-E) photos, tag extraction, etc.. "urls.txt" is meant to be a CSV-file. This allows to add additional info like blog name (if you have multiple blogs in your account, keywords, external URLs, ...)

    The beauty of the tumblr library is that it generates real links. No redirects, no nofollow-tags on these. 100% pure link juice.

    Please feel free to use the idea, the code, etc. in your business idea. I have no commercial interests in sharing this code. My motivation lies in contributing something to the GSA platform and community, having learned so much from it myself.
  • Thank you for your contribution.

    It has been a while since we moved on from Tumblr.

    However, I still have a few questions.

    Does Tumblr provide a do-follow backlink from the post itself, or do we still need to include it in the bio section?

    Are they strict about banning users if they receive spam?
  • malcom said:

    Does Tumblr provide a do-follow backlink from the post itself, or do we still need to include it in the bio section?

    Are they strict about banning users if they receive spam?
    It is a do-follow backlink from the post itself.

    I've not encountered any ban but have to admit that the posts made where not pure spam but content in "Tumblr-language" and relevant to the respective outlink.
  • organiccastle  hey just wondering you said this will post to "expired" tumblr blogs.

    Do you mean expired only or just "precreated" as I understand there is no front end script to create and verify new blogs currently.

    So as long as you have access to the tumblr api and the login credentials with a blog thats set up it work like that?

    Am I correct assumming this?

    Also, If I test, find useful and optimize to become a billionaire overnight, I will throw you a million :wink:
  • You are right @backlinkaddict, the tumblr account + blog(s) need to be precreated outside of this script.

    Expired blogs can be more beneficial though as you don't need to do all of the warming-up by following/unfollowing, commenting, sharing anymore. Publishing only articles and building backlinks to these does ignore lots of power and traffic the platform still has.
    Thanked by 1backlinkaddict
  • As side note anyone using openai scripts with certain models will have to adapt there models on there endpoint URLS.

    So if any scripts you are using break, it may be as simple to fix as switching the  "text-davinci-003" for example in the following -

    https://api.openai.com/v1/engines/text-davinci-003/completions

    to one of these . . . gpt-4, gpt-4 turbo, gpt-3.5-turbo


    As of today  Jan 4Th, these models are retired . . . 
    • text-ada-001
    • text-babbage-001
    • text-curie-001
    • text-davinci-001
    • text-davinci-002
    • text-davinci-003
    • davinci-instruct-beta
    • curie-instruct-beta
    • code-search-ada-code-001
    • code-search-ada-text-001
    • code-search-babbage-code-001
    • code-search-babbage-text-001
    • text-search-ada-doc-001
    • text-search-ada-query-001
    • text-search-babbage-doc-001
    • text-search-babbage-query-001
    • text-search-curie-doc-001
    • text-search-curie-query-001
    • text-search-davinci-doc-001
    • text-search-davinci-query-001
    • text-similarity-ada-001
    • text-similarity-babbage-001
    • text-similarity-curie-001
    • text-similarity-davinci-001
    • text-davinci-edit-001
    • code-davinci-edit-001
    • text-davinci-insert-001
    • text-davinci-insert-002

    If your developing anything on your own and hit a wall, don't give up!

    Keep pushing on!

    Code is just art that does something and I hope you can make something amazing this year!
Sign In or Register to comment.