-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: use author identifiers in import API #10110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
19a1566
5912f75
8305af5
280d715
a3b8412
810dc33
9d54ff7
0be86b7
f57f997
82b198c
87d9f25
f9a43c5
047211c
18541e8
e525c23
6473fbb
c8e43b8
419016a
00c3dff
a2af74a
309daa9
e47f5cb
a8cd195
01c2576
c730dd0
bab3f89
8596a3b
a3d9a24
9bbf023
ec13685
a1251ad
9c9cc48
a615f26
253ed32
3f42068
a9456f8
9563baf
6faf88d
6facf5b
cd051af
43b3aaa
b9ab864
d904ec1
7c9f483
37f173e
6fa2c1a
4895023
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| from openlibrary.core.ratings import Ratings | ||
| from openlibrary.core.vendors import get_amazon_metadata | ||
| from openlibrary.core.wikidata import WikidataEntity, get_wikidata_entity | ||
| from openlibrary.plugins.upstream.utils import get_identifier_config | ||
| from openlibrary.utils import extract_numeric_id_from_olid | ||
| from openlibrary.utils.isbn import canonical, isbn_13_to_isbn_10, to_isbn_13 | ||
|
|
||
|
|
@@ -806,6 +807,32 @@ def get_edition_count(self): | |
| def get_lists(self, limit=50, offset=0, sort=True): | ||
| return self._get_lists(limit=limit, offset=offset, sort=sort) | ||
|
|
||
| def merge_remote_ids( | ||
| self, incoming_ids: dict[str, str] | ||
| ) -> tuple[dict[str, str], int]: | ||
| """Returns the author's remote IDs merged with a given remote IDs object, as well as a count for how many IDs had conflicts. | ||
| If incoming_ids is empty, or if there are more conflicts than matches, no merge will be attempted, and the output will be (author.remote_ids, -1). | ||
| """ | ||
| output = {**self.remote_ids} | ||
pidgezero-one marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ended up having to revert to this deconstruction - self.remote_ids is being treated as a Thing and not a dict, for some reason (despite every other operation on it in this codebase suggesting it should be a dict) so deepcopy fails. I'm stumped on why that's happening. |
||
| if len(incoming_ids.items()) == 0: | ||
pidgezero-one marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return output, -1 | ||
| # Count | ||
| matches = 0 | ||
| conflicts = 0 | ||
| config = get_identifier_config("author") | ||
| for id in config["identifiers"]: | ||
| identifier: str = id.name | ||
| if identifier in output and identifier in incoming_ids: | ||
| if output[identifier] != incoming_ids[identifier]: | ||
| conflicts = conflicts + 1 | ||
| else: | ||
| output[identifier] = incoming_ids[identifier] | ||
pidgezero-one marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| matches = matches + 1 | ||
| if conflicts > matches: | ||
|
||
| # TODO: Raise this to librarians, somehow. | ||
| return self.remote_ids, -1 | ||
| return output, matches | ||
|
|
||
|
|
||
| class User(Thing): | ||
| def get_default_preferences(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Temporary requirements for running standalone scripts that are not necessary for OL to function. | ||
| # Run like this: | ||
| # python -m pip install -r requirements_scripts.txt && PYTHONPATH=. python ./path/to/script.py optional_args... && python -m pip uninstall -y -r requirements_scripts.txt | ||
|
|
||
| mwparserfromhell==0.6.6 | ||
| nameparser==1.1.3 | ||
| wikitextparser==0.56.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to name this one as
keyto be consistent with our book/thing records. Having the import endpoint mirror the shape of our core book records is convenient.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Freso do you have any strong opinions on this? ^
(see also Drini's comment above about remote_ids vs identifiers!)