~josealberto4444/apodnasabot

e7a4c2ad94e43016218838efd3bae7739dadc5fa — José Alberto Orejuela García 2 years ago 7373fb9
Download and save image
4 files changed, 15 insertions(+), 1 deletions(-)

M .gitignore
M README.md
M api.py
M init.sh
M .gitignore => .gitignore +3 -0
@@ 1,2 1,5 @@
# Config file with API keys and tokens
config.cfg

# Data folder
data

M README.md => README.md +2 -1
@@ 48,7 48,8 @@ Execute the initialization script:
This will do the following steps:

1. Create the configuration file `config.cfg` if it does not exist.
2. Create the python virtual environment if it's not created yet.
1. Create the directory for storing data called `data`.
1. Create the python virtual environment if it's not created yet and install all the dependencies.




M api.py => api.py +6 -0
@@ 24,3 24,9 @@ baseurl = 'https://api.nasa.gov/planetary/apod'
payload = {'api_key': api_key}
r = requests.get(baseurl, params = payload)
api_response = r.json()

r = requests.get(api_response['hdurl'])
filename = 'data/' + api_response['date'] + '.jpg'
with open(filename, 'wb') as f:
    for chunk in r.iter_content(chunk_size=128):
        f.write(chunk)

M init.sh => init.sh +4 -0
@@ 19,6 19,10 @@ if [ ! -f "config.cfg" ]; then
    cp "config.cfg.new" "config.cfg"
fi

if [ ! -d "data" ]; then
    mkdir data
fi

if [ "$1" = "dev" ]; then
    pipenv install --three --dev --skip-lock
else