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

tasks.py 1.5 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
  1. import sys
  2. from pathlib import Path
  3. import subprocess as sp
  4. import os
  5. import logging
  6. from invoke import task, Collection
  7. import ratings, support, viaf, openlib, loc, analyze, goodreads
  8. from colorama import Fore as F, Back as B, Style as S
  9. _log = logging.getLogger(__package__)
  10. _log_fmt = '%(asctime)s %(levelname)s %(name)s: %(message)s'
  11. _log_date = '%H:%M:%S'
  12. try:
  13. import chromalog
  14. chromalog.basicConfig(stream=sys.stderr, level=logging.INFO, format=_log_fmt, datefmt=_log_date)
  15. except ImportError:
  16. logging.basicConfig(stream=sys.stderr, level=logging.INFO, format=_log_fmt, datefmt=_log_date)
  17. _log.warning('chromalog not found, using plain logs')
  18. @task
  19. def status(c):
  20. with support.database() as db, db.cursor() as cur:
  21. cur.execute('SELECT step, started_at, finished_at, finished_at - started_at AS elapsed FROM import_status ORDER BY started_at')
  22. for step, start, end, time in cur:
  23. if end:
  24. print(f'{S.BRIGHT}{step}{S.RESET_ALL}: {F.GREEN}finished{S.RESET_ALL} at {end} (took {time})')
  25. else:
  26. print(f'{S.BRIGHT}{step}{S.RESET_ALL}: {F.YELLOW}started{S.RESET_ALL} at {start}')
  27. ns = Collection()
  28. ns.add_task(status)
  29. ns.add_collection(support)
  30. ns.add_collection(ratings)
  31. ns.add_collection(viaf)
  32. ns.add_collection(openlib)
  33. ns.add_collection(loc)
  34. ns.add_collection(analyze)
  35. ns.add_collection(goodreads)
  36. if __name__ == '__main__':
  37. import invoke.program
  38. program = invoke.program.Program()
  39. program.run()
Tip!

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

Comments

Loading...