-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
40 lines (32 loc) · 810 Bytes
/
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
import requests
import json
import pandas as pd
import random
def data():
df = pd.read_csv('./gravity.csv', encoding='ISO-8859-1')
a = df.to_json(orient="records")
b = json.loads(a)
return b
def star_img(star_name):
URL = "https://images-api.nasa.gov/search?q=" + str(star_name)
a = requests.get(URL)
b = a.json()
c = dict(b)
d = c.get("collection")
try :
e = d["items"][0]
except IndexError:
e = ""
else :
pass
if e != "":
df = pd.json_normalize(e)
f = df.get("href")[0]
g = requests.get(f)
h = g.json()
ia = list(h)
j = len(ia) - 2
k = ia[random.randint(0,j)]
return k
else :
return "ImageNotFound"