Only retweet if a specific hashtag is in a tweet with the Retweet Bot

You need to retweet tweets with a specific hashtag from another Twitter account to your own account? Just use the Retweet bot!

retweet

Configuration to retweet all tweets with a specific hashtag

Here is a complete example of a Retweet configuration to retweet all tweets with a specific hashtag. In this example every tweets with the hashtag #rt from the carl_chenet Twitter account will be retweeted to the Twitter account with the credentials above:

[twitter]
screen_name_of_the_user_to_retweet=carl_chenet
consumer_key=ml9jaiBnf3pmU9uIrKNIxAr3v
consumer_secret=8Cmljklzerkhfer4hlj3ljl2hfvc123rezrfsdctpokaelzerp
access_token=213416590-jgJnrJG5gz132nzerl5zerwi0ahmnwkfJFN9nr3j
access_token_secret=3janlPMqDKlunJ4Hnr90k2bnfk3jfnwkFjeriFZERj32Z

[retweet]
only_if_hashtags=rt,

[sqlite]
sqlitepath=/var/lib/retweet/retweet.db

The [twitter] section uses the screen_name_of_the_user_to_retweet parameter to define which Twitter account should be listened to. The other parameters of this section are the Twitter credentials you need to automatically tweet (see the Configure chapter of the official Retweet bot documentation).

The [retweet] section does use here only one parameter only_if_hashtags. You just need a comma-separated string of your hashtags (without the hash).

The [sqlite] section only needs the sqlitepath parameter with a path to the Sqlite database storing the ids of the already-retweeted tweets.

Install and set up the Retweet bot

Ok now we have a complete Retweet configuration to retweet only if the hashtag #rt appears in the tweets. Now lets install Retweet:

# pip3 install retweet

Then lets create a retweet user with the home /var/lib/retweet:

# adduser --home /var/lib/retweet --gecos "" retweet

The proper way to store our configuration file is to put it in the /etc/retweet directory:

# mkdir -p /etc/retweet /var/lib/retweet
# chown -R retweet:root /etc/retweet /var/lib/retweet

Now lets write our configuration file with the sections and the parameters defined above. You also have a full example available in the Configure section of the official Retweet documentation.

# vi /etc/retweet/retweet.ini

Almost ready! Last step: write a line in the crontab in order to launch Retweet on a regular basis:

*/10 * * * retweet retweet /etc/retweet/retweet.ini

And voila! Your Retweet bot is ready.

More information about the Retweet bot

… and finally

You can help the Retweet Bot by donating anything through Liberaypay (also possible with cryptocurrencies). That’s a big factor motivation 😉

10 thoughts on “Only retweet if a specific hashtag is in a tweet with the Retweet Bot

    • In the configuration file :
      [twitter]
      screen_name_of_the_user_to_retweet=carl_chenet

      means you’re going to retweet everything from the @carl_chenet Twitter account.

      Just use the complete article and you’ll be able to retweet everything from the Twitter account you use as above.
      To create the app to get the Twitter credentials: https://apps.twitter.com

  1. Hi,

    If you add some features, can be achieved?

    1. multi-user

    E.g. screen_name_of_the_user_to_retweet = user1, user2, user …

    2. min_retweets and min_faves and filtering RT, it’s important.

    You can ignore this problem.

    Thank you!

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *