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 1.9 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
  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 %s', infile)
  19. s.pipeline([
  20. [s.bin_dir / 'import-json', '--truncate', 'openlib', 'author', infile]
  21. ])
  22. s.finish('ol-authors')
  23. @task(s.build, s.init)
  24. def import_editions(c, date='2018-10-31', force=False):
  25. "Import OpenLibrary editions"
  26. s.check_prereq('ol-init')
  27. s.start('ol-editions', force=force)
  28. infile = s.data_dir / f'ol_dump_editions_{date}.txt.gz'
  29. _log.info('importing OL editions from %s', infile)
  30. s.pipeline([
  31. [s.bin_dir / 'import-json', '--truncate', 'openlib', 'edition', infile]
  32. ])
  33. s.finish('ol-editions')
  34. @task(s.build, s.init)
  35. def import_works(c, date='2018-10-31', force=False):
  36. "Import OpenLibrary works"
  37. s.check_prereq('ol-init')
  38. s.start('ol-works', force=force)
  39. infile = s.data_dir / f'ol_dump_works_{date}.txt.gz'
  40. _log.info('importing works from %s', infile)
  41. s.pipeline([
  42. [s.bin_dir / 'import-json', '--truncate', 'openlib', 'work', infile]
  43. ])
  44. s.finish('ol-works')
  45. @task(s.init)
  46. def index(c, force=False):
  47. "Index OpenLibrary data"
  48. s.check_prereq('ol-works')
  49. s.check_prereq('ol-editions')
  50. s.check_prereq('ol-authors')
  51. s.start('ol-index', force=force)
  52. _log.info('building OpenLibrary indexes')
  53. s.psql(c, 'ol-index.sql')
  54. s.finish('ol-index')
Tip!

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

Comments

Loading...