mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-26 22:20:21 +00:00
33 lines
747 B
Python
33 lines
747 B
Python
|
__package__ = 'archivebox.legacy.storage'
|
||
|
|
||
|
from typing import List, Iterator
|
||
|
|
||
|
from ..schema import Link
|
||
|
from ..util import enforce_types
|
||
|
from ..config import setup_django
|
||
|
|
||
|
|
||
|
### Main Links Index
|
||
|
|
||
|
sql_keys = ('url', 'timestamp', 'title', 'tags', 'updated')
|
||
|
|
||
|
|
||
|
@enforce_types
|
||
|
def parse_sql_main_index() -> Iterator[Link]:
|
||
|
setup_django()
|
||
|
from core.models import Page
|
||
|
|
||
|
return (
|
||
|
page.as_json(*sql_keys)
|
||
|
for page in Page.objects.all()
|
||
|
)
|
||
|
|
||
|
@enforce_types
|
||
|
def write_sql_main_index(links: List[Link]) -> None:
|
||
|
setup_django()
|
||
|
from core.models import Page
|
||
|
|
||
|
for link in links:
|
||
|
info = {k: v for k, v in link._asdict().items() if k in sql_keys}
|
||
|
Page.objects.update_or_create(url=link.url, defaults=info)
|