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.1 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
71
72
73
74
75
76
  1. import logging
  2. from invoke import task
  3. import support as s
  4. _log = logging.getLogger(__name__)
  5. dft_date = '2018-10-31'
  6. @task(s.init)
  7. def init(c, force=False):
  8. "Initialize the OpenLibrary schema"
  9. if s.start('ol-init', fail=False, force=force):
  10. _log.info('initializing OpenLibrary schema')
  11. s.psql(c, 'ol-schema.sql')
  12. s.finish('ol-init')
  13. @task(s.build, s.init)
  14. def import_authors(c, date=dft_date, force=False):
  15. "Import OpenLibrary authors"
  16. s.check_prereq('ol-init')
  17. s.start('ol-authors', force=force)
  18. infile = s.data_dir / f'ol_dump_authors_{date}.txt.gz'
  19. _log.info('importing OL authors from %s', infile)
  20. s.pipeline([
  21. [s.bdtool, 'import-json', '--truncate', 'openlib', 'author', infile]
  22. ])
  23. s.finish('ol-authors')
  24. @task(s.build, s.init)
  25. def import_editions(c, date=dft_date, 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 %s', infile)
  31. s.pipeline([
  32. [s.bdtool, 'import-json', '--truncate', 'openlib', 'edition', infile]
  33. ])
  34. s.finish('ol-editions')
  35. @task(s.build, s.init)
  36. def import_works(c, date=dft_date, force=False):
  37. "Import OpenLibrary works"
  38. s.check_prereq('ol-init')
  39. s.start('ol-works', force=force)
  40. infile = s.data_dir / f'ol_dump_works_{date}.txt.gz'
  41. _log.info('importing works from %s', infile)
  42. s.pipeline([
  43. [s.bdtool, 'import-json', '--truncate', 'openlib', 'work', infile]
  44. ])
  45. s.finish('ol-works')
  46. @task(s.init)
  47. def index(c, force=False):
  48. "Index OpenLibrary data"
  49. s.check_prereq('ol-works')
  50. s.check_prereq('ol-editions')
  51. s.check_prereq('ol-authors')
  52. s.start('ol-index', force=force)
  53. _log.info('building OpenLibrary indexes')
  54. s.psql(c, 'ol-index.sql')
  55. s.finish('ol-index')
  56. @task(s.init, s.build)
  57. def record_files(c, date=dft_date):
  58. files = [s.data_dir / f'ol_dump_{x}_{date}.txt.gz' for x in ['authors', 'editions', 'works']]
  59. s.booktool(c, 'hash', *files)
Tip!

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

Comments

Loading...