This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from gilesknap/restore-bad-ids
Restore bad ids
- Loading branch information
Showing
13 changed files
with
184 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from pathlib import Path | ||
from yaml import safe_load, safe_dump, YAMLError | ||
from typing import Dict | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class BadIds: | ||
""" keeps a list of media items with ID in a YAML file. The YAML file | ||
allows a user to easily investigate their list of media items that have | ||
failed to download | ||
Attributes: | ||
items: Dict[str, Item] bad ids found with identifying attributes | ||
bad_ids_filename: str: file where ids are stored/read | ||
bad_ids_found: count of Ids found since instantiation | ||
""" | ||
|
||
def __init__(self, root_folder: Path): | ||
self.items: Dict[str, dict] = {} | ||
self.bad_ids_filename: Path = root_folder / "gphotos.bad_ids.yaml" | ||
self.bad_ids_found: int = 0 | ||
self.load_ids() | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.store_ids() | ||
|
||
def load_ids(self): | ||
try: | ||
with self.bad_ids_filename.open("r") as stream: | ||
self.items = safe_load(stream) | ||
log.debug("bad_ids file, loaded %d bad ids", len(self.items)) | ||
except (YAMLError, IOError): | ||
log.debug("no bad_ids file, bad ids list is empty") | ||
|
||
def store_ids(self): | ||
with self.bad_ids_filename.open("w") as stream: | ||
safe_dump(self.items, stream, default_flow_style=False) | ||
|
||
def add_id(self, path: str, gid: str, product_url: str, e: Exception): | ||
item = dict(path=str(path), product_url=product_url) | ||
self.items[gid] = item | ||
log.debug("BAD ID %s for %s", gid, path, exc_info=e) | ||
|
||
def check_id_ok(self, gid: str): | ||
if gid in self.items: | ||
self.bad_ids_found += 1 | ||
return False | ||
else: | ||
return True | ||
|
||
def report(self): | ||
if self.bad_ids_found > 0: | ||
log.error( | ||
"WARNING: skipped %d files listed in %s", | ||
self.bad_ids_found, | ||
self.bad_ids_filename, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"access_token": "ya29.a0Ae4lvC1ZBRSQCX8BWo5pWXFmLuxo50RbV3jqzHAcC6_uNeuNJh5gZI3fyoDbYOZkZg5S5Xjup5XuLFTOj7318Lxl7sZidUI6ECpyiqawDqyjzqI-0oRoXLklZYUTA3A6NJu12JXc1crIBbGkybJz0FCGnhFOF3FBXknR", "expires_in": 3599, "scope": ["https://www.googleapis.com/auth/photoslibrary.sharing", "https://www.googleapis.com/auth/photoslibrary.readonly"], "token_type": "Bearer", "expires_at": 1587844377.5515726, "refresh_token": "1//03Yu7zu9SJvECCgYIARAAGAMSNwF-L9IrQJfYtnhVFpOHX_0Qq2-O2si6CtUvk9MDJ3mF7CH5bUqqFiSoeXxvnQE4mfD_k01wBtM"} | ||
{"access_token": "ya29.a0AfH6SMD35EBX1lN2t6VhxFeqhrnjc90Z28Go4RY2V7EYVH2biHQtpidr2-dC6VPvY5C6tbQmLAUGuI1Ba6ArQWv0tLfQlYenNGNyNuNwMlsTBqi97ozirEYV86Bgegdrav592HIk0Azf7q1TIzh2_gqDBBRjWQc4cUYT", "expires_in": 3599, "scope": ["https://www.googleapis.com/auth/photoslibrary.sharing", "https://www.googleapis.com/auth/photoslibrary.readonly"], "token_type": "Bearer", "expires_at": 1589309491.7933416, "refresh_token": "1//03Yu7zu9SJvECCgYIARAAGAMSNwF-L9IrQJfYtnhVFpOHX_0Qq2-O2si6CtUvk9MDJ3mF7CH5bUqqFiSoeXxvnQE4mfD_k01wBtM"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.