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
|
- import logging
- from invoke import task
- import support as s
- _log = logging.getLogger(__name__)
- @task(s.init)
- def init(c, force=False):
- "Initialize the OpenLibrary schema"
- if s.start('ol-init', fail=False, force=force):
- _log.info('initializing OpenLibrary schema')
- s.psql(c, 'ol-schema.sql')
- s.finish('ol-init')
- @task(s.build, s.init)
- def import_authors(c, date='2018-10-31', force=False):
- "Import OpenLibrary authors"
- s.check_prereq('ol-init')
- s.start('ol-authors', force=force)
- infile = s.data_dir / f'ol_dump_authors_{date}.txt.gz'
- _log.info('importing OL authors from', infile)
- s.pipeline([
- [s.bin_dir / 'clean-json', '--openlib', infile],
- ['psql', '-c', '\\copy ol.author (author_key, author_data) FROM STDIN']
- ])
- s.finish('ol-authors')
- @task(s.build, s.init)
- def import_editions(c, date='2018-10-31', force=False):
- "Import OpenLibrary editions"
- s.check_prereq('ol-init')
- s.start('ol-editions', force=force)
- infile = s.data_dir / f'ol_dump_editions_{date}.txt.gz'
- _log.info('importing OL editions from', infile)
- s.pipeline([
- [s.bin_dir / 'clean-json', '--openlib', infile],
- ['psql', '-c', '\\copy ol.edition (edition_key, edition_data) FROM STDIN']
- ])
- s.finish('ol-editions')
- @task(s.build, s.init)
- def import_works(c, date='2018-10-31', force=False):
- "Import OpenLibrary works"
- s.check_prereq('ol-init')
- s.start('ol-works', force=force)
- infile = s.data_dir / f'ol_dump_works_{date}.txt.gz'
- s.pipeline([
- [s.bin_dir / 'clean-json', '--openlib', infile],
- ['psql', '-c', '\\copy ol.work (work_key, work_data) FROM STDIN']
- ])
- s.finish('ol-works')
- @task(s.init)
- def index(c, force=False):
- "Index OpenLibrary data"
- s.check_prereq('ol-works')
- s.check_prereq('ol-editions')
- s.check_prereq('ol-authors')
- s.start('ol-index', force=force)
- _log.info('building OpenLibrary indexes')
- s.psql(c, 'ol-index.sql')
- s.finish('ol-index')
|