2019-04-17 07:49:18 +00:00
|
|
|
__package__ = 'archivebox.legacy.storage'
|
|
|
|
|
|
|
|
from typing import List, Iterator
|
|
|
|
|
|
|
|
from ..schema import Link
|
|
|
|
from ..util import enforce_types
|
2019-04-19 01:09:54 +00:00
|
|
|
from ..config import setup_django, OUTPUT_DIR
|
2019-04-17 07:49:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
### Main Links Index
|
|
|
|
|
|
|
|
@enforce_types
|
2019-04-19 01:09:54 +00:00
|
|
|
def parse_sql_main_index(out_dir: str=OUTPUT_DIR) -> Iterator[Link]:
|
|
|
|
setup_django(out_dir, check_db=True)
|
2019-04-17 07:49:18 +00:00
|
|
|
from core.models import Page
|
|
|
|
|
|
|
|
return (
|
2019-04-24 08:06:54 +00:00
|
|
|
Link.from_json(page.as_json(*Page.keys))
|
2019-04-17 07:49:18 +00:00
|
|
|
for page in Page.objects.all()
|
|
|
|
)
|
|
|
|
|
|
|
|
@enforce_types
|
2019-04-19 01:09:54 +00:00
|
|
|
def write_sql_main_index(links: List[Link], out_dir: str=OUTPUT_DIR) -> None:
|
|
|
|
setup_django(out_dir, check_db=True)
|
2019-04-17 07:49:18 +00:00
|
|
|
from core.models import Page
|
|
|
|
|
|
|
|
for link in links:
|
2019-04-17 07:50:41 +00:00
|
|
|
info = {k: v for k, v in link._asdict().items() if k in Page.keys}
|
2019-04-17 07:49:18 +00:00
|
|
|
Page.objects.update_or_create(url=link.url, defaults=info)
|