Better Programming

Advice for programmers.

Follow publication

Member-only story

How To Use Python To Post on Popular Blogging Websites

Rahul Banerjee
Better Programming
Published in
8 min readSep 26, 2022
Screenshot showing the automation process

In this article, we will use Python to automate the following tasks:

  • Creating gists for your code snippets
  • Embed gists into the article with different requirements for WordPress, Medium, Dev.to, and Hashnode
  • Post the article on WordPress
  • Post the article on Medium with WordPress canonical link
  • Post the article on Dev.to with WordPress canonical link
  • Post the article on Hashnode with WordPress canonical link

Essentially, we will be using Python to automate cross-posting to multiple websites. We will be using various APIs for doing the above tasks.

You can find all the code in my GitHub repo.

Setting Up the Project

First, create a new folder for the project:

mkdir crossPoster
cd crossPoster

Next, create a virtual environment and activate it, as shown below:

python3 -m venv venvsource venv/bin/activate

Install the required libraries, as shown below:

pip3 install requests, Markdown, python-dotenv

Create a file named .env in your root directory. This will be used to store all your credentials. You will also need a test markdown file to be able to cross-post. In this tutorial, I am going to assume that all the images have public URLs and are not loaded from local files.

1️. How To Use GitHub API To Create Gists for Code Snippets

Before proceeding, we will need a GitHub token. Go to your developer settings token page to get your GitHub token. When creating the token, make sure the option “Create Gist” is checked. This allows you to create gists using your GitHub token. Copy the token and save it in your .env file.

GITHUB_TOKEN = "YOUR_GITHUB_TOKEN"

First, we will need to write a function to get all the code snippets from a markdown…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Rahul Banerjee
Rahul Banerjee

Written by Rahul Banerjee

Software Developer | Views are my own

No responses yet

Write a response