bookwyrm-social / bookwyrm

Social reading and reviewing, decentralized with ActivityPub
http://joinbookwyrm.com/
Other
2.28k stars 267 forks source link

Readwise integration #1603

Open nycterent opened 3 years ago

nycterent commented 3 years ago

It would be nice to be able to sync highlights/notes from Readwise to Bookwyrm and back.

https://readwise.io/

They have an API that could be used for this feature.

ozer550 commented 2 years ago

Hi there, I know the basics of Django and would like to contribute to this idea. Can you guide me on how should I proceed? :)

mouse-reeve commented 2 years ago

I don't have a clear idea going in of what this should look like, but I'd be happy to suss it out together!

When we talk about syncing data between apps, there are two fairly different things involved - copying data from bookwyrm to readwise, and copying data from readwise to bookwyrm. Off the top of my head, I think it would entail something like this:

BookWyrm to Readwise (this is not simple, but sounds doable)

In this use case, someone posts a quote on bookwyrm and that quote is sent to their readwise account. It looks like they use title and author to determine the book, which will be straightforward to provide.

  1. Let bookwyrm users add a Readwise authentication token to their account
    • This probably makes sense to add to the user model, and include in the user settings views
  2. Send BookWyrm data to readwise when a quote is created (https://readwise.io/api_deets, Highlight CREATE)
    • If the user has a Readwise integration, create a celery background task to update readwise when a quote is created
    • In the celery task, generate a json blob in their expected format
    • Send an http POST to readwise with the json blob, and then readwise can sort out the rest
  3. Delete or update readwise highlights when the bookwyrm quote is deleted or updated

Readwise to BookWyrm (this is a lot harder)

  1. Authenticate Readwise (same as 1 above)
  2. Fetch readwise data about a book (https://readwise.io/api_deets Highlights LIST)
    • It doesn't appear that Readwise will proactively send data when a highlight is created, so this will have to happen periodically, or when a user manually triggers a sync
  3. Interpret the readwise data and create a BookWyrm status from it
    • Readwise will provide a book_id field with each highlight, which will have to be looked up since it won't mean anything to BookWyrm on it's own. I didn't see how to do this in the API documentation.
    • Once a usable book identifier is acquired (like an ISBN or title and author), it will need to be matched with a book in the instance database. If the book isn't present or can't be found, it's not clear what should happen.
    • If a book is found, a quote can be created from the text field provided in the API response - but it will need to check if that highlight has already been created so that they aren't re-imported every time a sync happens
nycterent commented 2 years ago

BookWyrm to Readwise (this is not simple, but sounds doable)

Readwise is mostly highlight resurfacing service, so if this part: BookWyrm to Readwise would be implemented - that would be awesome. Afaik deleting is not important use case as you can do it in readwise and it is part of using Readwise flow.

On Sat, Feb 12, 2022 at 19:30:36, Mouse Reeve @.***> wrote:

I don't have a clear idea going in of what this should look like, but I'd be happy to suss it out together!

When we talk about syncing data between apps, there are two fairly different things involved - copying data from bookwyrm to readwise, and copying data from readwise to bookwyrm. Off the top of my head, I think it would entail something like this: BookWyrm to Readwise (this is not simple, but sounds doable)

In this use case, someone posts a quote on bookwyrm and that quote is sent to their readwise account. It looks like they use title and author to determine the book, which will be straightforward to provide.

  1. Let bookwyrm users add a Readwise authentication token to their account

    • This probably makes sense to add to the user model, and include in the user settings views
  2. Send BookWyrm data to readwise when a quote is created (https:// readwise.io/api_deets https://readwise.io/api_deets, Highlight CREATE )

    • If the user has a Readwise integration, create a celery background task to update readwise when a quote is created
    • In the celery task, generate a json blob in their expected format
    • Send an http POST to readwise with the json blob, and then readwise can sort out the rest
  3. Delete or update readwise highlights when the bookwyrm quote is deleted or updated

Readwise to BookWyrm (this is a lot harder)

  1. Authenticate Readwise (same as 1 above)

  2. Fetch readwise data about a book (https://readwise.io/api_deets Highlights LIST)

    • It doesn't appear that Readwise will proactively send data when a highlight is created, so this will have to happen periodically, or when a user manually triggers a sync
  3. Interpret the readwise data and create a BookWyrm status from it

    • Readwise will provide a book_id field with each highlight, which will have to be looked up since it won't mean anything to BookWyrm on it's own. I didn't see how to do this in the API documentation.
    • Once a usable book identifier is acquired (like an ISBN or title and author), it will need to be matched with a book in the instance database. If the book isn't present or can't be found, it's not clear what should happen.
    • If a book is found, a quote can be created from the text field provided in the API response - but it will need to check if that highlight has already been created so that they aren't re-imported every time a sync happens

— Reply to this email directly, view it on GitHub https://github.com/bookwyrm-social/bookwyrm/issues/1603#issuecomment-1037333404, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAATZ3MGKNEREXMONT6TAZ3U22KLZANCNFSM5H6Q4ETA . You are receiving this because you authored the thread.Message ID: @.***>

mouse-reeve commented 2 years ago

Thank you -- I think implementing just posting from bookwyrm to readwise would be very achievable and I'm glad to hear that that sounds like a useful piece! There's still a lot of unknowns for me about how well it would work, since I haven't used Readwise, but I'd be happy to support if taking on that chunk of what I mentioned above sounds good, @ozer550

carlos210609 commented 1 year ago

i have a finished code for this do you want ?

mouse-reeve commented 1 year ago

yes! definitely

carlos210609 commented 1 year ago

ok in the code you just need the api key do you have it?

carlos210609 commented 1 year ago

of course you have lol