From c854d54922d6410d6d77d3bf0583fe5b920f90a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20=E2=80=9CFreso=E2=80=9D=20S=2E=20Olesen?= Date: Mon, 26 Aug 2024 07:12:30 +0200 Subject: [PATCH] Read Work identifiers from file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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] https://github.com/internetarchive/openlibrary/issues/9234 https://github.com/internetarchive/openlibrary/pull/9483 [2] https://github.com/internetarchive/openlibrary/issues/9666 https://github.com/internetarchive/openlibrary/pull/9769 [3] https://github.com/internetarchive/openlibrary/issues/3430 --- .../openlibrary/config/work/identifiers.yml | 22 ++++++++++++++++ openlibrary/plugins/upstream/utils.py | 26 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 openlibrary/plugins/openlibrary/config/work/identifiers.yml diff --git a/openlibrary/plugins/openlibrary/config/work/identifiers.yml b/openlibrary/plugins/openlibrary/config/work/identifiers.yml new file mode 100644 index 000000000000..4728bdb6c1fe --- /dev/null +++ b/openlibrary/plugins/openlibrary/config/work/identifiers.yml @@ -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 diff --git a/openlibrary/plugins/upstream/utils.py b/openlibrary/plugins/upstream/utils.py index 5a05afc2317d..6bcac4ce2140 100644 --- a/openlibrary/plugins/upstream/utils.py +++ b/openlibrary/plugins/upstream/utils.py @@ -1261,6 +1261,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