Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

openlib.py 2.0 KB

You have to be logged in to leave a comment. Sign In
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
  1. import logging
  2. from invoke import task
  3. import support as s
  4. _log = logging.getLogger(__name__)
  5. @task(s.init)
  6. def init(c, force=False):
  7. "Initialize the OpenLibrary schema"
  8. if s.start('ol-init', fail=False, force=force):
  9. _log.info('initializing OpenLibrary schema')
  10. s.psql(c, 'ol-schema.sql')
  11. s.finish('ol-init')
  12. @task(s.build, s.init)
  13. def import_authors(c, date='2018-10-31', force=False):
  14. "Import OpenLibrary authors"
  15. s.check_prereq('ol-init')
  16. s.start('ol-authors', force=force)
  17. infile = s.data_dir / f'ol_dump_authors_{date}.txt.gz'
  18. _log.info('importing OL authors from', infile)
  19. s.pipeline([
  20. [s.bin_dir / 'clean-json', '--openlib', infile],
  21. ['psql', '-c', '\\copy ol_author (author_key, author_data) FROM STDIN']
  22. ])
  23. s.finish('ol-authors')
  24. @task(s.build, s.init)
  25. def import_editions(c, date='2018-10-31', force=False):
  26. "Import OpenLibrary editions"
  27. s.check_prereq('ol-init')
  28. s.start('ol-editions', force=force)
  29. infile = s.data_dir / f'ol_dump_editions_{date}.txt.gz'
  30. _log.info('importing OL editions from', infile)
  31. s.pipeline([
  32. [s.bin_dir / 'clean-json', '--openlib', infile],
  33. ['psql', '-c', '\\copy ol_edition (edition_key, edition_data) FROM STDIN']
  34. ])
  35. s.finish('ol-editions')
  36. @task(s.build, s.init)
  37. def import_works(c, date='2018-10-31', force=False):
  38. "Import OpenLibrary works"
  39. s.check_prereq('ol-init')
  40. s.start('ol-works', force=force)
  41. infile = s.data_dir / f'ol_dump_works_{date}.txt.gz'
  42. s.pipeline([
  43. [s.bin_dir / 'clean-json', '--openlib', infile],
  44. ['psql', '-c', '\\copy ol_work (work_key, work_data) FROM STDIN']
  45. ])
  46. s.finish('ol-works')
  47. @task(s.init)
  48. def index(c, force=False):
  49. "Index OpenLibrary data"
  50. s.check_prereq('ol-works')
  51. s.check_prereq('ol-editions')
  52. s.check_prereq('ol-authors')
  53. s.start('ol-index', force=force)
  54. _log.info('building OpenLibrary indexes')
  55. s.psql(c, 'ol-index.sql')
  56. s.finish('ol-index')
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...