-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathold_dates_update.py
37 lines (30 loc) · 1017 Bytes
/
old_dates_update.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
import os
from app import db
from util import run_sql
def old_dates_update():
"""
This function updates data by pulling 5 old dates from the past year.
When run once each day, the entire past year will update every 73 days.
"""
# pick 5 oldest dates from past year
date_sql = """
SELECT * FROM doi_queue_paperbuzz_dates
WHERE id > now() - interval '1 year'
ORDER BY finished ASC NULLS FIRST LIMIT 5;
"""
dates = db.session.execute(date_sql)
# set values to null so they are picked up by importer
for date in dates:
id_date = date[0]
run_sql(
db,
"""update doi_queue_paperbuzz_dates
set enqueued=NULL, finished=NULL, started=NULL, dyno=NULL
where id = '{id_date}'""".format(
id_date=id_date
),
)
# run update script
os.system("python doi_queue.py --dates --run")
if __name__ == "__main__":
old_dates_update()