forked from ncats/RDAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver_automatic.py
More file actions
91 lines (76 loc) · 3.02 KB
/
driver_automatic.py
File metadata and controls
91 lines (76 loc) · 3.02 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import sys
workspace = os.path.dirname(os.path.abspath(__file__))
sys.path.append(workspace)
import argparse
import clinical.update, pubmed.update, grant.update
from datetime import date,datetime
from AlertCypher import AlertCypher
from time import sleep
from gard.methods import get_node_counts
from subprocess import *
def check_update(db_type):
db = AlertCypher('gard')
today = datetime.now()
config_selection = {'ct':['clinical_update', 'ct_interval'], 'pm':['pubmed_update', 'pm_interval'], 'gnt':['grant_update', 'gnt_interval']}
selection = config_selection[db_type]
last_update = db.getConf('DATABASE',selection[0])
last_update = datetime.strptime(last_update,"%m/%d/%y")
delta = today - last_update
interval = db.getConf('DATABASE',selection[1])
interval = int(interval)
last_update = datetime.strftime(last_update,"%m/%d/%y")
if delta.days > interval:
print('UPDATE TRIGGERED')
return [True,last_update]
else:
print('UPDATE NOT TRIGGERED')
return [False,last_update]
parser = argparse.ArgumentParser()
parser.add_argument("-db", "--database", dest = "db", help="Database name")
parser.add_argument("-u", "--update-from", dest="date", help="Set date to update from")
args = parser.parse_args()
if args.db == 'ct':
if args.date:
print('Clinical Trial Update does not require --update-from date')
else:
while True:
update_data = check_update(args.db)
if update_data[0]:
clinical.update.main()
get_node_counts()
p = Popen(['sudo', 'python3', 'generate_dump.py', '-dir clinical', '-b', '-t', '-s dev'], encoding='utf8')
p.wait()
sleep(3600)
elif args.db == 'pm':
if args.date:
while True:
update_data = check_update(args.db)
if update_data[0]:
pubmed.update.main(update_from=args.date.strftime("%d/%m/%y"))
get_node_counts()
p = Popen(['sudo', 'python3', 'generate_dump.py', '-dir pubmed', '-b', '-t', '-s dev'], encoding='utf8')
p.wait()
sleep(3600)
else:
while True:
update_data = check_update(args.db)
if update_data[0]:
pubmed.update.main(update_from=update_data[1])
get_node_counts()
p = Popen(['sudo', 'python3', 'generate_dump.py', '-dir pubmed', '-b', '-t', '-s dev'], encoding='utf8')
p.wait()
sleep(3600)
elif args.db == 'gnt':
if args.date:
print('Grant Update does not require --update-from date')
else:
while True:
if check_update(args.db):
grant.update.main()
get_node_counts()
p = Popen(['sudo', 'python3', 'generate_dump.py', '-dir grant', '-b', '-t', '-s dev'], encoding='utf8')
p.wait()
sleep(3600)
else:
print(r'Invalid arguments/flags [TRY: python3 driver_automatic.py -db {ct/pm/gnt} -u 06/30/23]')