Skip to content

Commit

Permalink
Read Work identifiers from file
Browse files Browse the repository at this point in the history
This is taking the same steps applied to editions[1] and authors[2] and
applying it to works. `get_work_config()` is currently not used for
anything, probably because we’re still waiting for an actual interface
to edit the Work identifiers[3], so this is more a preliminary step to
ensure that Works will be handled in the same way that Editions and
Authors are. (And to allow for PRs to add Work identifiers while waiting
for that UI.)

[1] #9234
    #9483
[2] #9666
    #9769
[3] #3430
  • Loading branch information
Freso committed Aug 27, 2024
1 parent 9c4db66 commit 662ef2c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
22 changes: 22 additions & 0 deletions openlibrary/plugins/openlibrary/config/work/identifiers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
identifiers:
- label: BookBrainz
name: bookbrainz
url: https://bookbrainz.org/work/@@@
website: https://bookbrainz.org
- label: Книга Файнфиков
name: ficbook
notes: ''
url: https://ficbook.net/readfic/@@@
- label: MusicBrainz
name: musicbrainz
url: https://musicbrainz.org/work/@@@
website: https://musicbrainz.org
- label: MyAnimeList
name: myanimelist
notes: ''
url: https://myanimelist.net/manga/@@@
- label: Wikidata
name: wikidata
notes: ''
url: https://www.wikidata.org/wiki/@@@
website: https://wikidata.org
26 changes: 26 additions & 0 deletions openlibrary/plugins/upstream/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,32 @@ def _get_edition_config():
)


@public
def get_work_config() -> Storage:
"""Returns the work config.
This just calls _get_work_config(). See that
function's documentation for further details.
"""
return _get_work_config()


@web.memoize
def _get_work_config() -> Storage:
"""Returns the work config.
The results are cached on the first invocation.
The /config/work page currently has no unique options so we
don't load/fetch it here currently.
"""
with open('openlibrary/plugins/openlibrary/config/work/identifiers.yml') as in_file:
id_config = yaml.safe_load(in_file)
identifiers = [
Storage(id) for id in id_config.get('identifiers', []) if 'name' in id
]
return Storage(identifiers=identifiers)


from openlibrary.core.olmarkdown import OLMarkdown


Expand Down

0 comments on commit 662ef2c

Please sign in to comment.