mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-27 21:24:16 -04:00
first working django model with archivebox-shell command and sql exporting
This commit is contained in:
parent
ecf95d398a
commit
cdb70c73df
17 changed files with 215 additions and 21 deletions
32
archivebox/legacy/storage/sql.py
Normal file
32
archivebox/legacy/storage/sql.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
__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)
|
Loading…
Add table
Add a link
Reference in a new issue