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 ! ! !

    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.
  • 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 1[Deleted User]
Sign In or Register to comment.