mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-14 15:14:31 -04:00
support loading link indexes with extra keys
This commit is contained in:
parent
98870ba428
commit
19e1c35f1a
2 changed files with 10 additions and 4 deletions
|
@ -120,12 +120,18 @@ def write_json_links_index(out_dir: str, links: List[Link]) -> None:
|
|||
def parse_json_links_index(out_dir: str=OUTPUT_DIR) -> Iterator[Link]:
|
||||
"""parse a archive index json file and return the list of links"""
|
||||
|
||||
allowed_fields = {f.name for f in fields(Link)}
|
||||
|
||||
index_path = os.path.join(out_dir, 'index.json')
|
||||
if os.path.exists(index_path):
|
||||
with open(index_path, 'r', encoding='utf-8') as f:
|
||||
links = json.load(f)['links']
|
||||
for link in links:
|
||||
yield Link(**link)
|
||||
for link_json in links:
|
||||
yield Link(**{
|
||||
key: val
|
||||
for key, val in link_json.items()
|
||||
if key in allowed_fields
|
||||
})
|
||||
|
||||
return ()
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ class Link:
|
|||
from util import ts_to_date
|
||||
|
||||
most_recent = min(
|
||||
(result.start_ts
|
||||
(ts_to_date(result.start_ts)
|
||||
for method in self.history.keys()
|
||||
for result in self.history[method]),
|
||||
default=None,
|
||||
|
@ -176,7 +176,7 @@ class Link:
|
|||
from util import ts_to_date
|
||||
|
||||
most_recent = max(
|
||||
(result.start_ts
|
||||
(ts_to_date(result.start_ts)
|
||||
for method in self.history.keys()
|
||||
for result in self.history[method]),
|
||||
default=None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue