mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-17 08:34:26 -04:00
refactor: All parsers return snapshot instead of link
This commit is contained in:
parent
15d88be229
commit
b8efaa5b6a
11 changed files with 72 additions and 53 deletions
|
@ -6,7 +6,8 @@ import re
|
|||
from typing import IO, Iterable
|
||||
from datetime import datetime
|
||||
|
||||
from ..index.schema import Link
|
||||
from django.db.models imort Model
|
||||
|
||||
from ..util import (
|
||||
htmldecode,
|
||||
enforce_types,
|
||||
|
@ -14,8 +15,9 @@ from ..util import (
|
|||
|
||||
|
||||
@enforce_types
|
||||
def parse_netscape_html_export(html_file: IO[str], **_kwargs) -> Iterable[Link]:
|
||||
def parse_netscape_html_export(html_file: IO[str], **_kwargs) -> Iterable[Model]:
|
||||
"""Parse netscape-format bookmarks export files (produced by all browsers)"""
|
||||
from core.models import Snapshot
|
||||
|
||||
html_file.seek(0)
|
||||
pattern = re.compile("<a href=\"(.+?)\" add_date=\"(\\d+)\"[^>]*>(.+)</a>", re.UNICODE | re.IGNORECASE)
|
||||
|
@ -29,11 +31,11 @@ def parse_netscape_html_export(html_file: IO[str], **_kwargs) -> Iterable[Link]:
|
|||
time = datetime.fromtimestamp(float(match.group(2)))
|
||||
title = match.group(3).strip()
|
||||
|
||||
yield Link(
|
||||
yield Snapshot(
|
||||
url=htmldecode(url),
|
||||
timestamp=str(time.timestamp()),
|
||||
title=htmldecode(title) or None,
|
||||
tags=None,
|
||||
sources=[html_file.name],
|
||||
#tags=None,
|
||||
#sources=[html_file.name],
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue