-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (37 loc) · 1.46 KB
/
main.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
import os
from dotenv import dotenv_values
# import time
from app import crawl, line
parms = dict()
# fetch secrets from .env file
try:
config = dotenv_values(".env")
parms['api_key'] = config['API_KEY']
except:
parms['api_key'] = 'DEMO_KEY'
print("Credentials file not found, using limited 'DEMO_KEY'\n")
service = input("Select service:\n[1] Crawl\n[2] Lookup object\n[3] Feed (disabled)\n[4] Generate chart\n")
## Browse data
if (service == '1'):
# example request: https://api.nasa.gov/neo/rest/v1/neo/browse?api_key=DEMO_KEY
parms['page'] = 1
parms['size'] = 20
total = parms['page'] + 1
baseUrl = 'https://api.nasa.gov/neo/rest/v1/neo/browse?'
while int(parms['page']) <= int(total):
total = crawl.crawl(baseUrl, parms, total)
## Lookup NEO object
if (service == '2'):
# example request: https://api.nasa.gov/neo/rest/v1/neo/3542519?api_key=DEMO_KEY
print(crawl.lookup(input('Input object name or id:\n'), parms))
## Get data feed
if (service == '3'):
# example: https://api.nasa.gov/neo/rest/v1/feed?start_date=2015-09-07&end_date=2015-09-08&api_key=DEMO_KEY
baseUrl = 'https://api.nasa.gov/neo/rest/v1/feed?'
parms['start_date'] = '2020-09-20'
parms['end_date'] = '2020-09-25'
if (service == '4'):
inp = input("Set year range [from,to]:\n")
encounters = line.approach(inp.split(','))
if (line.jsonify(encounters)):
print('Plot generated, open file://'+os.getcwd()+'/www/index.html')