You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a suggestion to fix an issue with paginating results for the Highlight EXPORT API endpoint. In addition, requesting to add two new API endpoint method calls: Highlight EXPORT and Daily Review LIST. See the description below (pulled from Readwise API docs):
Highlight EXPORT - If you want to pull all of the highlights from a user's account into your service (eg notetaking apps, backups, etc) this endpoint is all you need!
I'd be happy to submit a PR to implement these changes, including updating documentation and tests if the configuration is approved.
Potential Configuration
Highlight EXPORT
I suggest fixing the pagination issue in the _get_pagination() method with a simple expression to check the endpoint parameter equals "/endpoint/", allowing it to paginate the pages correctly without affecting the other endpoints that use the old pagination technique. No new code is added as it's the same code as the _get_pagination() in ReadwiseReader class.
def_get_pagination(
...
) ->Generator[dict, None, None]:
...
ifendpoint=="/export/":
# taken from `ReadwiseReader` class `_get_pagination` methodpageCursor=NonewhileTrue:
ifpageCursor:
params.update({"pageCursor": pageCursor})
logging.debug(f'Getting page with cursor "{pageCursor}"')
try:
response=getattr(self, get_method)(endpoint, params=params)
exceptChunkedEncodingError:
logging.error(f'Error getting page with cursor "{pageCursor}"')
sleep(5)
continuedata=response.json()
yielddataif (
isinstance(data, list)
ornotdata.get("nextPageCursor")
ordata.get("nextPageCursor") ==pageCursor
):
breakpageCursor=data.get("nextPageCursor")
else:
# same code as before
Once that is fixed, it is possible to add a new generator method in the Readwise class to call the export endpoint. Below is my suggested implementation.
defexport_highlights(
self, updated_after: str=None, ids: list[str] =None
) ->Generator[ReadwiseExportResults, None, None]:
""" Export all highlights from Readwise. Args: updated_after: date highlight was last updated ids: A list of book ids Yields: A generator of ReadwiseExportResults objects """params= {}
ifupdated_after:
params["updatedAfter"] =updated_afterifids:
params["ids"] =",".join(_idfor_idinids)
fordatainself.get_pagination_limit_20("/export/", params):
forbookindata["results"]:
book_tags= [ReadwiseTag(**book_tag) forbook_taginbook["book_tags"]]
highlights= [
ReadwiseExportHighlight(
tags=[ReadwiseTag(**tag) fortaginhighlight["tags"]],
**{
key: valueforkey, valueinhighlight.items()
ifkey!="tags"
},
)
forhighlightinbook["highlights"]
]
yieldReadwiseExportResults(
**{
key: valueforkey, valueinbook.items()
ifkeynotin ["book_tags", "highlights"]
},
book_tags=book_tags,
highlights=highlights,
)
Daily Review LIST
These methods work with the existing codebase as it does not rely on pagination.
I think adding these models will help with data management from the new methods: ReadwiseExportResults, ReadwiseExportHighlight, DailyReviewHighlight, and ReadwiseDailyReview.
References
I came across this issue because I use this package to get highlights for my Readwise to Apple Notes export CLI tool and noticed the export endpoint did not get all of my highlights. See issue at Scarvy/readwise-to-apple-notes#4.
Community Note
Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
If you are interested in working on this issue or have submitted a pull request, please leave a comment
The text was updated successfully, but these errors were encountered:
Description
This is a suggestion to fix an issue with paginating results for the Highlight EXPORT API endpoint. In addition, requesting to add two new API endpoint method calls:
Highlight EXPORT
andDaily Review LIST
. See the description below (pulled from Readwise API docs):Highlight EXPORT - If you want to pull all of the highlights from a user's account into your service (eg notetaking apps, backups, etc) this endpoint is all you need!
Daily Review LIST - Returns your daily review highlights
I'd be happy to submit a PR to implement these changes, including updating documentation and tests if the configuration is approved.
Potential Configuration
Highlight EXPORT
I suggest fixing the pagination issue in the
_get_pagination()
method with a simple expression to check theendpoint
parameter equals "/endpoint/", allowing it to paginate the pages correctly without affecting the other endpoints that use the old pagination technique. No new code is added as it's the same code as the_get_pagination()
inReadwiseReader
class.Once that is fixed, it is possible to add a new generator method in the
Readwise
class to call the export endpoint. Below is my suggested implementation.Daily Review LIST
These methods work with the existing codebase as it does not rely on pagination.
Dataclass models
I think adding these models will help with data management from the new methods:
ReadwiseExportResults
,ReadwiseExportHighlight
,DailyReviewHighlight
, andReadwiseDailyReview
.References
I came across this issue because I use this package to get highlights for my Readwise to Apple Notes export CLI tool and noticed the
export
endpoint did not get all of my highlights. See issue at Scarvy/readwise-to-apple-notes#4.Community Note
The text was updated successfully, but these errors were encountered: