NASA APOD (Astronomy Picture of the Day) Twitter Bot
This Python script uses the NASA APOD API to retrieve the "Astronomy Picture of the Day" and posts it to Twitter. It also includes functionality to handle both image and video media types.
A Video Explaining the Project
Prerequisites
- Python 3
- The following Python modules:
requests
requests_oauthlib
json
shutil
Setup
- Replace the placeholder values in the script with your own Twitter API and NASA API keys:
CLIENT_ID
CLIENT_SECRET
TOKEN_KEY
TOKEN_SECRET
NASA_API
- Run the script using
python3 nasa_apod_twitter_bot.py
How it works
The script follows these steps:
- Makes a GET request to the NASA APOD API to retrieve the "Astronomy Picture of the Day" data
- Downloads the image or video thumbnail (depending on the media type)
- Uploads the image or video to Twitter's media upload endpoint to get a media ID
- Posts the media ID and title of the "Astronomy Picture of the Day" to Twitter's status update endpoint