forked from vai2fc/apulian
/
biblio.py
executable file
·70 lines (48 loc) · 1.58 KB
/
biblio.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
#!/usr/bin/env python3
"""\
This queries JStore to get references for all the items in the apulian
database.
"""
import argparse
import sys
from apulian.models import bootstrap, Vase
from populate import DB_NAME
N = 10
def jstor(query_str, n):
"""Takes a query string and returns up to n results from dfr.jstor.org. """
def make_searches(vase):
"""Takes a vase and returns queries for it."""
params = {
'ch': vase.trendall_ch,
'no': vase.trendall_no,
'city': vase.location.city_name,
'col': vase.location.collection_name,
'id': vase.location.collection_id,
}
return [
'trendall {ch}.{no}'.format(**params),
'trendall {ch}/{no}'.format(**params),
'{city} {id}'.format(**params),
'{col} {id}'.format(**params),
]
def parse_args(argv=None):
"""Parse command-line arguments."""
argv = argv if argv is not None else sys.argv[1:]
p = argparse.ArgumentParser(description=__doc__)
p.add_argument('-n', '--n', dest='n', action='store', default=N, type=int,
help='The number of items to return in each search. '
'Default = {}.'.format(N))
args = p.parse_args()
return args
def main():
"""The main entrypoint for this process."""
args = parse_args()
make_session = bootstrap(
'sqlite:///{}'.format(DB_NAME),
)
session = make_session()
for vase in session.query(Vase).order_by(Vase.produced_start):
for query_str in make_searches(vase):
pass
if __name__ == '__main__':
main()