-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnasa_data.py
63 lines (47 loc) · 1.33 KB
/
nasa_data.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""NASA data
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1P8FHsTUiB8unE5AZfjDMTwyKDVwbZXmw
Get the media urls from NASA API
"""
import json
import requests
gallery = []
topics = ["apollo", "artemis"]
def get_data(api):
response = requests.get(f"{api}", params={"keywords": "artemis"})
if response.status_code == 200:
print("sucessfully fetched the data")
return response.json()
else:
print(f"There's a {response.status_code} error with your request")
# Get Responses
data = get_data('https://images-api.nasa.gov/search?q=apollo')
# Print the first element of the collection
# print(data['collection']['items'][0])
# Data Extract
items = data['collection']['items']
mediaUrl = []
for item in items:
mediaUrl.append(item['links'][0]['href'])
for url in mediaUrl:
# Print the index:
print(mediaUrl.index(url))
print(url)
"""
from google.colab import drive
drive.mount('/content/gdrive')
root_path = 'gdrive/My Drive/NASA_media/' #change dir to project folder
import os
import urllib.request
from tqdm import tqdm
for url in tqdm(mediaUrl):
try:
#print(str(url))
!wget -q "$url" -P "/content/gdrive/My Drive/NASA_Media" # type: ignore
#urllib.request.urlretrieve(url)
except Exception as e:
print(e)
pass
"""