-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_spacex.py
26 lines (21 loc) · 861 Bytes
/
fetch_spacex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import requests
import os
from PIL import Image
import utils
from pathlib import Path
def fetch_spacex_launch_urls(launch_number):
spacex_url = 'https://api.spacexdata.com/v3/launches/{}'.format(launch_number)
response = requests.get(spacex_url)
response.raise_for_status()
unpacked_response = response.json()
spacex_pictures_urls = unpacked_response['links']['flickr_images']
return spacex_pictures_urls
if __name__ == "__main__":
launch_number = 'latest'
folder_path = (Path.cwd() / 'Space Pictures')
mission = 'spacex'
image_id = 0
pictures_urls = fetch_spacex_launch_urls(launch_number)
picture_request_response = utils.get_pictures(pictures_urls, mission)
utils.download_pictures(picture_request_response, folder_path, pictures_urls, mission, image_id)
utils.thumbnail_pictures(folder_path)