This is a simple script which uses the Twitter API to search and retweet tweets containing the word 'alfajor' or 'alfajores'. Can be adapted for any other word the user may prefer.
Note: As of March 28, 2023, the original bot account has been suspended for violating Twitter's rules.
The script reads three different variables from the environment: TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET,
and BANNED_WORDS
TWITTER_CONSUMER_KEY: OAuth 1.0a Consumer Key, found in the Twitter Developer PortalTWITTER_CONSUMER_SECRET: OAuth 1.0a Consumer Secret, found in the Twitter Developer PortalBANNED_WORDS: A,,,separated list of words that when present in a Tweet will make the script skip it
This link contains more info about the Twitter API and how to request an application.
I personally prefer to export/set these variables at the start of my cron file, but you can also set them in .bashrc for example.
This script requires Twitter API v2, so you will need elevated access.
This script needs access to your bot's Twitter Account.
- The first time it is run, an authorization URL will be printed out on your screen, which you will have to open on your browser while logged into your bot's account
- If everything is working correctly, the page should display an authorization box, by clicking "Authorize app", you are allowing your application to control the account
- After you clicked that button, you will see a PIN, copy it to the console where the script is running and press enter
- Now the access tokens will be stored in a JSON file, and you won't need to authorize the application again