A Twitter bot using the NASA API
About • How To Use • Set-Up • Related • Contact
A twitter bot that replies to requests with random images from NASA's Image Gallery fetched using NASA's Open API. It also posts daily NASA's Astronomy Picture of the Day(APOD). You can also request the bot for APOD of a specific date and it will respond accordingly.
- Does not repeat images.
- Supports banning images
- Supports blocking specific users.
- All config done using separete settings file.
- Tweet "Hey @TheNasaBot" for a random image pulled from NASA's Image Library
- Tweet "Hey @TheNasaBot #keyword" to get am image matching the keyword - eg. #Jupiter
- Tweet "Hey @TheNasaBot send APOD for #YYYY-MM-DD" to get NASA's Astronomy Picture of the Day for the specified date - eg. #2021-02-10
-
Requirements:
- python3
- tweepy
pip install tweepy
- requests
pip install requests
- Twitter developer account
-
Files setup:
- Rename all
sample-filename
files tofilename
- Complete the
settings/settings
file with appropriate details
(Detailed explaination below) - Finally setup a cron job to run
twitterbot.py
Eg.* * * * * python3 /path/to/bot/twitterbot.py
- Rename all
-
Monitoring:
- You can use a service like Cronitor to monitor the bot and get notified in case of any errors.
twt_api_key
- Twitter consumer keytwt_secret_key
- Twitter consumer key secrettwt_token
- Twitter access keytwt_secret_token
- Twitter access key secretnasa_api_key
- NASA API key (Get it here.)allow_repeat_after
- After how many images the bot is allowed to repeat an imageapod_time
- Time in HH:MM format (24 hours) when the bot should post the daily APODbot_account
- @Username of the bot accountmaster_account
- @Username of the bot manager/owner accounttemp_downloads
- Full path to a folder where bot can download images temporarilysearch_terms
- [list] of search terms the bot should use when looking for images. (The bot will choose a random image from the search results)ban_command
- Keyword that the manager/owner can tweet under any reply from the bot. This will result in the bot deleting that reply and it will not post that image again.request_commands
- Keyword/s that the users can use when requesting an image from the bot. For multiple keywords, add each on a new line.time_tolerance
- Time (in minutes) for how old a request tweet should be for it to be ignored.tweet_text
- Optional text which will be added to the begining of every tweet by the bot
- twitterImgBot - Source for twitter bot components
- Twitter Developer Account
- tweepy-docs
- NASA API Details