Skip to content
Pelican-Twitter bridge
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Pelican-Twitter Bridge

This set of Python scripts are aimed at allowing users of the Pelican blog engine to link some of their posts to Twitter.


For now, I only wrote two scripts:


The first one is useful to automatically post a tweet on Twitter for the latest blog post. As Pelican is text-based and often used with Git, this script makes use of Git logs to find new posts. More details are given below.

The second script posts a tweet on Twitter for each article posted on the blog in the last 7 days. Like the previous script, I give some details below.


Just fork this repo! :)

Since I use two external libraries, you also need to install them if you want to use these scripts.


Located at, the steps for installing it are :

hg clone python-twitter
cd python-twitter
hg update
python build
python install

Alternatively, you can now use:

pip install python-twitter


To shorten links, I use Bitly. This API is available in Pip repository, so installation is quite easy.

pip install bitly_api

The results of requests made to Bitly API are Unicode encoded, so I also need a library to re-encode them. This library is Unidecode. If you have a better way to work with Bitly, I will appreciate if you can tell me about!

git clone unidecode
python build
python install


The script need some configuration. For this, use the file


In this script, you have to define four variables for the Twitter API:


And two variables for the Bitly API. For now, Bitly is required in, but I plan to make it optional. It's already optional for


You can also define in a variable the base directory of you Pelican blog. This option is optional.

BASE_DIR = '~/pelican_blog/'

You can define whether the script will publish your blog by setting:

always_publish = True

You can define the tweet trigger word to be used in the metadata (Triggers:)

tweet_trigger = 'tweet'

Now, you can use the scripts.


I use this script to tweet the link of my last blog post.


This script do 4 things :

  1. It checks if a new article was written by checking the git repo.
  2. In this case, it pushes the new commits on the default git repository [FR].
  3. It updates the blog on the server through SSH (command make ssh_upload for the Pelican-ists).
  4. It post metadata contains Triggers: tweet - it will post a tweet.

Long explanation

I use Git to backup my blog. After each new blog post, I commit the new file with a commit message that starts with [POST]. I adapted the script to my own needs, so it get the last commit message, and if the message starts with [POST], it tweets it.

Before posting a tweet, the script pushes the new commits to the default Git repository, and updates the blog using Pelican Makefile.

The script gets the title and the URL of the lasts posts directly from the source file. If there are many files involved in the commit, every file that is located in content/ and has a .md or .rst extension will be considered as one of the lasts posts for which a tweet will be send.

Tweet text

The tweet message is constructed based on a format given by the user.

This configuration is set in, with the variable TWEET_FORMAT_AUTO. It's simply a string that contains variables, that will be replaced by real values during execution of the script.

Available variables are :

  • $$POST_TITLE$$ : Will be replaced by the title of the article.
  • $$POST_URL$$ : Will be replaced by the URL of the article.

If the variable TWEET_FORMAT_AUTO is not defined, the default one will be used :


The post title and URL come from the post source file. $$POST_TITLE$$ is the title of the post (post variable Title:). To construct the URL, the script extract the URL of the site in the file (variable SITEURL=), and append to it the slug of the blog post (variable Slug: in the header of the blog post file).


To launch the script, you have some options.

  1. Run it directly from the root of your Pelican directory: $ python ~/
  2. Run it from anywhere, and give it the path to the root of your Pelican directory: $ python ~/ ~/pelican_blog/


This script sends one tweet for each blog post published in the last few days.

I use the same method I used for the previous script to get the URL of the posts, or their title.

Number of days for which posts should be considered as new

By default, the value is 7 days.

This value can be modified in (here, 14 days):


Time between two Twitter updates

By default, each tweet is sent 3 minutes (180seconds) after the previous one.

It's possible to use a different interval using a variable in the configuration file (here, 60 seconds):


Tweet text

3 types of tweets are sent :

  1. TWEET_SUMMARY_BEGIN : A message to inform that the « blog replay » is starting.
  2. TWEET_FORMAT_SUMMARY : A message for each post.
  3. TWEET_SUMMARY_END_ONE and TWEET_SUMMARY_END_MANY : A message to inform that the « blog replay » is finished.

The first tweet can (or not) contains one variable : the name/url of the website. For this, use $$BLOG_URL$$. A second variable is mandatory. Place %d anywhere you want, and this variable will be replaced by the number of days for which we check for new posts. Exemple : Here are the articles posts in the last %d days on $$BLOG_URL$$ will become Here are the articles posts in the last 7 days on If you don't want to use send a first tweet, just set the IS_TWEET_SUMMARY_BEGIN variable to False in the configuration file :


The second tweet can contains variables like for (see above).

There are two cases for the last tweet :

  1. Only one new post was posted. The TWEET_SUMMARY_END_ONE is sent (no variable allowed).
  2. Many posts were posted. The TWEET_SUMMARY_END_MANY is sent. One variable is mandatory. Add %d in your text. This will be replaced by the numbered of new posts. Exemple : There were %d articles will become There were 24 articles.

As for the first tweet, you can define the last tweet not to be sent. Set the IS_TWEET_SUMMARY_END variable to False in the configuration file :



All these 4 variables can be ommited, and will be replaced by default values :

TWEET_FORMAT_SUMMARY   = '#blogReplay $$POST_TITLE$$ $$POST_URL$$ #blog'
TWEET_SUMMARY_BEGIN    = '#blogReplay Voici les articles publiés ces 7 derniers jours sur $$BLOG_URL$$'
TWEET_SUMMARY_END_ONE  = '#blogReplay C'était le seul article publié cette semaine. Fin du spam! :)'
TWEET_SUMMARY_END_MANY = '#blogReplay C'était les %d articles publiés cette semaine. Fin du spam! :)'


The usage of this script is quite the same as the previous one

  1. Run it directly from the root of your Pelican directory: $ python ~/
  2. Run it from anywhere, and give it the path to the root of your Pelican directory: $ python ~/ ~/pelican_blog/


I wrote some posts on my blog about this script :

I also created the theme I use on my blog, which is available on Github.

Something went wrong with that request. Please try again.