-
Notifications
You must be signed in to change notification settings - Fork 1
/
updateDB.py
executable file
·65 lines (51 loc) · 1.79 KB
/
updateDB.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
64
65
#!/usr/bin/env python
import os
import argparse
from PyAstronomy import pyasl
from tornado.ioloop import IOLoop
from apscheduler.schedulers.tornado import TornadoScheduler
def tick():
print('Downloading exoplanetEU')
df = pyasl.ExoplanetEU2(forceUpdate=True)
df = df.getAllDataPandas()
df['name'] = [s.decode() if isinstance(s, bytes) else s for s in df['name']]
df['star_name'] = [s.decode() if isinstance(s, bytes) else s for s in df['star_name']]
path = 'sweetercat/data/exoplanetEU.csv'
df.to_csv(path, index=False)
print('Saved as exoplanetEU.csv')
def setup():
home = os.path.expanduser('~')
pya = os.path.join(home, 'PyAData')
print('Setup starting...')
if not os.path.exists(pya):
print('Creating dir and config file')
os.makedirs(pya)
with open(os.path.join(home, '.pyaConfigWhere'), 'w') as f:
f.write(pya)
print('Setup done!')
def parse_args():
"""Take care of all the argparse stuff.
:returns: the args Namespace
"""
parser = argparse.ArgumentParser(description='Update DB on schedule.')
parser.add_argument("-i", "--interval", help='Update interval in minutes',
type=int, default=15)
parser.add_argument("-n", "--now", help='Update DB now only.', action="store_true")
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
interval = args.interval
# Prepare PyAstronomy
setup()
if args.now:
# Single update
tick()
else:
print('Starting scheduler...')
scheduler = TornadoScheduler()
scheduler.add_job(tick, 'interval', minutes=interval)
scheduler.start()
try:
IOLoop.instance().start()
except (KeyboardInterrupt, SystemExit):
pass