This project helps to find and download picture taken:
- During SpaceX launches;
- by NASA, which are called Astronomy Picture of The day (APOD);
- by NASA, using DSCOVR's Earth Polychromatic Imaging Camera (EPIC).
Using the scripts fetch_apod.py, fetch_epic.py and fetch_spacex_images.py scripts you can download images and put in the directory you desire.
You can also publish uploaded photos to your Telegram channel with the scripts publish_1photo_tg.py and publish_all_photos_tg.py using the bot you created.
-
Firstly, you have to install python and pip (package-management system) if they haven't been already installed.
-
Create a virtual environment with its own independent set of packages using virtualenv/venv. It'll help you to isolate the project from the packages located in the base environment.
-
Install all the packages used in this project, in your virtual environment which you've created on the step 2. Use the
requirements.txtfile to install dependencies:pip install -r requirements.txt -
Tokens and other keys:
- You need to generate NASA API key to access NASA API used in the
fetch_apod.pyandfetch_epic.pyscripts. Be sure to save the resulting key. - To publish images via
publish_1photo_tg.pyorpublish_all_photos_tg.pyscript, you need to create a bot in Telegram. In order to do this, find@BotFatherand start a new conversation with it. Then send him/newbotto create a new Telegram bot and follow the instructions. The last step will give you the bot's access Token, which you need to save. - Enter the tg_chat_id of the channel (@example_channel) where you're going to publish photos using the bot, and don't forget to add the bot to the list of channel administrators.
- You need to generate NASA API key to access NASA API used in the
-
Create an
.envfile and locate it in the same directory where your project is. Copy and append your access token to.envfile like this:NASA_API_KEY=paste_here_your_token_from_step_4.1 TG_BOT_TOKEN=paste_here_your_bot_token_from_step_4.2 TG_CHAT_ID=paste_here_your_chanel_name_from_step_4.3 -
Remember to add
.envto your.gitignoreif you are going to put the project on GIT.
Before using each of the scripts fetch_apod.py, fetch_epic.py, fetch_spacex_images.py, publish_1photo_tg.py and publish_all_photos_tg.py it is recommended to run them with optional argument -h to read the description and explore the features of the programs.
Run in your console:
>>> python3 fetch_apod.py -hOutput:
usage: fetch_apod.py [-h] [-p PATH] [-d DATE] [-s START_DATE] [-e END_DATE]
Program downloads Astronomy Picture Of the Day (APOD). If no date (or start_date, end_date) and path are given, the program will download pictures of the curent day and place picture(s) in the folder "images", located in the project
directory. If such a folder doesn't exist, it'll be created automatically.
options:
-h, --help show this help message and exit
-p PATH, --path PATH enter path to save the image
-d DATE, --date DATE enter date (YYYY-MM-DD) to download only 1 APOD
-s START_DATE, --start_date START_DATE
enter start_date for period to download a few APOD
-e END_DATE, --end_date END_DATE
enter end_date for period to download a few APODEach of the scripts individually:
-
The
fetch_apod.pyscript downloads the picture(s) for the current day, specified day or period and places them in the given path. If such a path doesn't exist, it'll be created automatically:Download picture for the current day and place it in the directory
path/to/save/images/:>>> python3 fetch_apod.py -p path/to/save/images/Download the picture for 2021/01/18 and put it in the
path/to/save/images/directory:>>> python3 fetch_apod.py -d 2021-01-18 -p path/to/save/images/Download photos taken from 2020/01/15 through 2020/01/18 and place them in the folder
images, located in the project directory. Remember, if such a folder doesn't exist, it'll be created automatically:>>> python3 fetch_apod.py -s 2020-01-15 -e 2020-01-18 -
The
fetch_epic.pyscript downloads natural color images of the Earth and puts them in a directory at the given path. If you don't specify an image extension and a path to save, the program will download image(s) with "PNG" extension and place them in the "images" folder located in the project directory. If such a folder doesn't exist, it'll be created automatically.Download the picture for current day and put it in the directory
path/to/save/images/:>>> python3 fetch_epic.py -p path/to/save/images/ -
The
fetch_spacex_images.pyscript downloads pictures of SpaceX launches. If no launch_id and path are given, the program will download photo(s) from the last launch and place them in the folder "images", located in the project directory. If such a folder doesn't exist, it'll be created automatically.Download images from the last launch and put it in the
path/to/save/images/directory:>>> python3 fetch_spacex_images.py -p path/to/save/images/Download pictures from the launch_id
5eb87d42ffd86e000604b384and place them in thepath/to/save/images/directory:>>> python3 fetch_spacex_images.py -i 5eb87d42ffd86e000604b384 -p path/to/save/images/ -
The
publish_1photo_tg.pyscript publishes one photo from the specified path or directory. If the path isn't given, the program will download APOD for the current day and publish it. After publishing, the picture will be deleted from the PC.Post the photo to the Telegram channel by specifying the photo path
enter/the/path/to/the/photo.png(сhat_id of the channel must be set in the.envfile.):>>> python3 publish_1photo_tg.py -p enter/the/path/to/the/photo.pngPost photo APOD for current day in the Telegram channel (tg_chat_id of the channel must be set in the
.envfile.):>>> python3 publish_1photo_tg.py -
The
publish_all_photos_tg.pyscript publishes all photos from a given directory path at a fixed interval, every 4 hours (by default). You can also loop publish photos from directory and subdirectories. After first publishing of all images, they will be shuffled to publish them in a different order.Post all the photos located in the
enter/the/path/to/the/imagesdirectory and set frequency of publication as every 6 hours:>>> python3 publish_all_photos_tg.py enter/the/path/to/the/images -f 6Post all the photos located in the
enter/the/path/to/the/imagesdirectory and subdirectories. Loop publish photos until the script wouldn't be stoped.>>> python3 publish_all_photos_tg.py enter/the/path/to/the/images -e
The code is written for educational purposes.