openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Include notes when exporting lists to other formats

Open Freso opened this issue 1 year ago • 1 comments

Problem

A clear and concise description of what you want to happen

When exporting lists, they should either include any notes attached to items in the list or provide an option to include the notes.

E.g. Go to https://openlibrary.org/people/ScarTissue/lists/OL233794L/TPL_Treasure_Sale_2023

Click the "HTML" or "JSON" options

Screenshots

adding a note to a book in a list

Additional Context

From @dcapillae on Slack:

Adding notes to the books included in an Open Library list is great because you can create annotated bibliographies to share with other readers. However, these notes are not exported when you export your lists to HTML, BibTex or JSON format. It would be interesting to be able to export your lists in Open Library including the notes you have added to each book.

Proposal & Constraints

Rough proposal:

  • Update the export endpoint https://github.com/internetarchive/openlibrary/blob/ceb273a02efd2372c6411b0e86e49529c4817c21/openlibrary/plugins/openlibrary/lists.py#L743 to have a new v parameter which defaults to 1. To avoid a breaking change to these APIs.
  • Update the list export method to instead of having the raw OL thing, have an object like { thing: THING, notes: notes }. See https://github.com/internetarchive/openlibrary/blob/f197acb2c3d23575ab9af05b2f27a061685723ba/openlibrary/core/lists/model.py#L212-L218
  • For HTML: Update lists/export_as_html.html to also display the notes and handle the nested dict
  • Handle v=1 returning just the thing directly; v=2 should return the wrapper {thing: THING, notes: notes}.

Leads

Related files

Stakeholders


Instructions for Contributors

  • Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.

Freso avatar Jul 29 '24 10:07 Freso

Hi, I'd like to work on this! Just to clarify, editions, works and authors all have notes associated with them?

ChinoUkaegbu avatar Oct 10 '24 08:10 ChinoUkaegbu

Hi @ChinoUkaegbu ! Apologies for the delay; if you're still interested, let me know and I will assign you!

Yes that is correct; lists on open library are either a raw reference to a edition/work/author (eg { key: "/works/OL123w" }) -- known in the code as a Seed, or a wrapping object called an AnnotatedSeed, eg: { thing: { key: "/works/OL123W" }, notes: "My note!" }.

I'd recommend updating this code: https://github.com/internetarchive/openlibrary/blob/f197acb2c3d23575ab9af05b2f27a061685723ba/openlibrary/core/lists/model.py#L204-L218

to

  1. Switch to using self.get_seeds() instead of self.seeds ; this will normalize the format
  2. change the things object to be a mapping of seed index to the item returned from the db ; that'll let you stitch them together with the notes
  3. If api=v2 is specified as a url parameter, return the annotated seed, eg { thing: <ITEM_FROM_DB>, notes: ... }

Hope that makes sense! Let me know if you want to be assigned or have any further questions :)

cdrini avatar Dec 24 '24 04:12 cdrini