This post on the Ghost forums ask for a way to automatically, and periodically tweet links to blog posts that are X days old. So, I made one.
GhostTweeter, is written in Python and uses tweepy and feedparser to cycle through a Ghost blog's RSS feed, get post information such as Title, URL, tags, and publish date. If a minimum age is set GhostTweeter will only tweet blog post older than the minimum age. GhostTweeter also turns your blog post tags into hashtags.
Tweets are sent in the following format:
<post title>: <url> #<tag1> #<tag2>
#Usage Before you can start the Python file you must get your Twitter authentication and replace this in your code.
- Go to https://apps.twitter.com/app/new and create a new app
- Once created, copy and paste your API key and secret (will be under "Keys and Access Tokens")
- Create an access token, copy and paste those as well
This is the Twitter authentication part of the Python code, anywehere you see 'yourshere' you must place the correct token.
# Twitter Auth CONSUMER_KEY = 'yourshere' CONSUMER_SECRET = 'yourshere' ACCESS_KEY = 'yourshere' ACCESS_SECRET = 'yourshere' auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) api = tweepy.API(auth)
##Running the code Once you have correctly entered your Twitter authentication info you must run the Python code. This code is written in Python 2.7 and will not work in Python 3 (yet). Open up your favorite Python terminal and type: *python GhostTweeter.py*
Now it will ask you for your Ghost url, as well as how often you want to tweet (in hours). Once that it all set you are ready to go!
Note: Depending on your OS, if you want to run this in the background you can simply run python GhostTweeter.py & and the code will do the rest of the work.
This code is very easy to change and can possibly be used with any RSS feed with some simple modifications.