generic_jsonl.py 690 B

1234567891011121314151617181920212223242526272829
  1. __package__ = 'archivebox.parsers'
  2. import json
  3. from typing import IO, Iterable
  4. from archivebox.misc.util import enforce_types
  5. from ..index.schema import Link
  6. from .generic_json import jsonObjectToLink
  7. def parse_line(line: str):
  8. if line.strip() != "":
  9. return json.loads(line)
  10. @enforce_types
  11. def parse_generic_jsonl_export(json_file: IO[str], **_kwargs) -> Iterable[Link]:
  12. """Parse JSONL format bookmarks export files"""
  13. json_file.seek(0)
  14. links = [ parse_line(line) for line in json_file ]
  15. for link in links:
  16. if link:
  17. yield jsonObjectToLink(link,json_file.name)
  18. KEY = 'jsonl'
  19. NAME = 'Generic JSONL'
  20. PARSER = parse_generic_jsonl_export