mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-23 03:06:55 -04:00
refactor: status command is functional
This commit is contained in:
parent
d92083b928
commit
973f8b6abc
5 changed files with 33 additions and 26 deletions
|
@ -42,7 +42,7 @@ from .html import (
|
|||
write_html_snapshot_details,
|
||||
)
|
||||
from .json import (
|
||||
load_json_snapshot_details,
|
||||
load_json_snapshot,
|
||||
parse_json_snapshot_details,
|
||||
write_json_snapshot_details,
|
||||
)
|
||||
|
@ -441,7 +441,7 @@ def get_duplicate_folders(snapshots, out_dir: Path=OUTPUT_DIR) -> Dict[str, Opti
|
|||
path = path.snapshot_dir
|
||||
|
||||
try:
|
||||
snapshot = parse_json_snapshot_details(path)
|
||||
snapshot = load_json_snapshot_details(path)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
@ -530,7 +530,7 @@ def is_valid(snapshot: Model) -> bool:
|
|||
if dir_exists and index_exists:
|
||||
try:
|
||||
# TODO: review if the `guess` was necessary here
|
||||
parsed_snapshot = parse_json_snapshot_details(snapshot.snapshot_dir)
|
||||
parsed_snapshot = load_json_snapshot(snapshot.snapshot_dir)
|
||||
return snapshot.url == parsed_snapshot.url
|
||||
except Exception:
|
||||
pass
|
||||
|
|
|
@ -91,17 +91,18 @@ def write_json_snapshot_details(snapshot: Model, out_dir: Optional[str]=None) ->
|
|||
|
||||
|
||||
@enforce_types
|
||||
def load_json_snapshot_details(out_dir: Path) -> Optional[Model]:
|
||||
def load_json_snapshot(out_dir: Path) -> Optional[Model]:
|
||||
"""
|
||||
Loads the detail from the local json index
|
||||
"""
|
||||
from core.models import Snapshot
|
||||
|
||||
existing_index = Path(out_dir) / JSON_INDEX_FILENAME
|
||||
if existing_index.exists():
|
||||
with open(existing_index, 'r', encoding='utf-8') as f:
|
||||
try:
|
||||
output = pyjson.load(f)
|
||||
if "history" not in output.keys():
|
||||
output["history"] = {}
|
||||
output = Snapshot.from_json(output)
|
||||
return output
|
||||
except pyjson.JSONDecodeError:
|
||||
pass
|
||||
|
@ -110,13 +111,13 @@ def load_json_snapshot_details(out_dir: Path) -> Optional[Model]:
|
|||
|
||||
@enforce_types
|
||||
def parse_json_snapshot_details(out_dir: Union[Path, str]) -> Iterator[dict]:
|
||||
"""read through all the archive data folders and return the parsed links"""
|
||||
"""read through all the archive data folders and return the parsed snapshots"""
|
||||
|
||||
for entry in os.scandir(Path(out_dir)):
|
||||
if entry.is_dir(follow_symlinks=True):
|
||||
if (Path(entry.path) / 'index.json').exists():
|
||||
try:
|
||||
snapshot_details = load_snapshot_details(entry.path)
|
||||
snapshot_details = load_json_snapshot_details(entry.path)
|
||||
except KeyError:
|
||||
snapshot_details = None
|
||||
if snapshot_details:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue