-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data.py
40 lines (29 loc) · 1 KB
/
get_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
from neos import Neo
import requests
import random
def get_from_neodys():
url = 'https://newton.dm.unipi.it/~neodys2/neo_name.list'
r = requests.get(url)
neos = []
for line in r.text.splitlines():
parts = line.split()
neo = {}
if len(parts) == 2:
neo['name'] = parts[1].strip()
neo['number'] = parts[0].strip()
elif len(parts) == 1:
neo['name'] = parts[0].strip()
neo['number'] = None
else:
continue
neo['absolute_magnitude'] = float(random.randrange(50, 500)) / 100
neo['slope_parameter'] = float(random.randrange(10, 100)) / 100
neo['perihelion'] = float(random.randrange(50, 300)) / 100
neo['aphelion'] = float(random.randrange(50, 300)) / 100
neos.append(neo)
Neo.insert_many(neos).execute()
if __name__ == "__main__":
Neo._meta.database.connect()
if not Neo.table_exists():
Neo._meta.database.create_tables([Neo])
get_from_neodys()