-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_mars_data.py
More file actions
53 lines (42 loc) · 1.55 KB
/
get_mars_data.py
File metadata and controls
53 lines (42 loc) · 1.55 KB
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
import requests
import secrets
BASE = "http://127.0.0.1:5000/mars_weather_data/"
FINAL_URL = f'https://api.nasa.gov/insight_weather/?api_key={secrets.api_key}&feedtype=json&ver=1.0'
sol_data = {}
def get_data():
response = requests.get(FINAL_URL)
if response.status_code != 200:
print(response.text)
return []
json_data = response.json()
available_sols = json_data["sol_keys"]
for sols in available_sols:
current_sol_data = {}
sol_json_data = json_data[sols]
sol_data["sol_id"] = sols
if "AT" in sol_json_data:
current_sol_data["temperature"] = sol_json_data["AT"]["av"]
else:
current_sol_data["temperature"] = None
if 'PRE' in sol_json_data:
current_sol_data["pressure"] = sol_json_data["PRE"]['av']
else:
current_sol_data["pressure"] = None
if 'HWS' in sol_json_data:
current_sol_data["horizontal_wind_speed"] = sol_json_data["HWS"]['av']
else:
current_sol_data["horizontal_wind_speed"] = None
if 'Season' in sol_json_data:
current_sol_data["season"] = sol_json_data['Season']
else:
current_sol_data["season"] = None
#print(str(sols), current_sol_data)
#results = str(sols), current_sol_data
response = requests.delete(BASE + str(sols))
response = requests.put(BASE + str(sols), current_sol_data)
result = response.status_code
return result
def main():
print(get_data())
if __name__ == '__main__':
main()