Twitterbot is a simple Python application for:
- reading and parsing a RSS feed and posting its title and links to a Twitter account.
- searching tweets for keywords or hashtags and retweet those tweets.
Both functions (Reading RSS and retweeting) can be used independently. The bot is limited to handle one feed and one Twitter account.
- Download or git clone Twitterbot:
git clone https://github.com/peterdalle/twitterbot
- Install dependencies feedparser and twython:
pip install feedparser
pip install twython
- Create a Twitter application, and generate keys, tokens etc.
- Modifiy the settings in the source code.
FeedUrlto the RSS feed you want to read.
- Modify the variables in the
TwitterAuthclass and add keys, tokens etc. for connecting to your Twitter app.
RetweetIncludeWordsfor keywords you want to search and retweet, and
RetweetExcludeWordsfor keywords you would like to exclude from retweeting. For example
RetweetIncludeWords = ["foo"]and
RetweetExcludeWords = ["bar"]will include any tweet with the word "foo", as long as the word "bar" is absent. This list can also be left empty, i.e.
RetweetExcludeWords = .
Read the RSS feed and post to Twitter account:
$ python twitterbot.py rss
Search for tweets and retweet them:
$ python twitterbot.py rt
Setup crontabs examples
Preferably, you should use crontab to set up Twitterbot to run on a schedule.
# Read RSS feed every hour and tweet new links. 00 * * * * python twitterbot.py rss # Rewteet keywords/hashtags every 15 minutes. */15 * * * * python twitterbot.py rt
Use the cron schedule expression editor to easily create crons.
See Questions and answers in the wiki.