-
Notifications
You must be signed in to change notification settings - Fork 4
/
oneoff.py
71 lines (60 loc) · 1.72 KB
/
oneoff.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
66
67
68
69
70
71
"""
Maintainance tasks that have needed to be done in the past
Mainly for reference
run as: FLASK_APP=oneoff.py flask add_posted_dates
"""
import click
from tqdm import tqdm
from sqlalchemy import desc
from models import Biorxiv
from webapp import app, rq, db, process_paper
from biorxiv_scraper import find_date
@app.cli.command()
def add_posted_dates():
"""Add dates to entries in database
updating the most recent first
"""
records = (Biorxiv.query
.filter_by(posted_date="")
.order_by(desc(Biorxiv.created))
.all())
for r in tqdm(records):
r.posted_date = find_date(r.id)
db.session.merge(r)
db.session.commit()
return
@app.cli.command()
@click.option('--head', default=None)
@click.option('--now', is_flag=True)
def rerun_missing(head=None, now=False):
"""Run unparsed papers
"""
query = Biorxiv.query.filter_by(parse_status=0)
if head:
query = query.limit(head)
elif now:
raise ValueError("Running everything now will be a headache!")
else:
query = query.all()
for rec in tqdm(query):
if now:
process_paper(rec)
else:
process_paper.queue(rec)
return
@app.cli.command()
@click.argument('paper_ids', nargs=-1)
@click.option('--now', is_flag=True)
def rerun():
n_queue = 0
for p in paper_ids:
if now:
rec = Biorxiv.query.filter_by(id=p).first()
process_paper(rec)
else:
n_queue += 1
process_paper.queue(rec)
print("Queued {} jobs".format(n_queue))
return
if __name__ == "__main__":
app.run(debug=True, threaded=True, use_reloader=False)