From 5d839f0a096df0b33f09262beb4c6351c70952b0 Mon Sep 17 00:00:00 2001 From: rwxd Date: Thu, 23 Feb 2023 19:08:22 +0100 Subject: [PATCH] fix(reader): support archived location --- wallabag2readwise/cli.py | 5 ++++- wallabag2readwise/models.py | 1 + wallabag2readwise/readwise.py | 12 +++++++++--- wallabag2readwise/wallabag.py | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/wallabag2readwise/cli.py b/wallabag2readwise/cli.py index 3e31192..9e55b40 100644 --- a/wallabag2readwise/cli.py +++ b/wallabag2readwise/cli.py @@ -87,7 +87,10 @@ def reader( wallabag_entries = wallabag.get_entries() for entry in wallabag_entries: console.print(f'=> Importing {entry.title}') - readwise.create(entry.url, tags=[t.label for t in entry.tags]) + location = 'archive' if entry.archived else 'new' + readwise.create( + entry.url, tags=[t.label for t in entry.tags], location=location + ) @app.command() diff --git a/wallabag2readwise/models.py b/wallabag2readwise/models.py index 06adf25..95159c8 100644 --- a/wallabag2readwise/models.py +++ b/wallabag2readwise/models.py @@ -17,6 +17,7 @@ class WallabagEntry: url: str hashed_url: str annotations: list + archived: bool tags: list[WallabagTag] diff --git a/wallabag2readwise/readwise.py b/wallabag2readwise/readwise.py index 6076584..0eef05b 100644 --- a/wallabag2readwise/readwise.py +++ b/wallabag2readwise/readwise.py @@ -2,11 +2,10 @@ from wallabag2readwise.logging import logger from typing import Generator from datetime import datetime -from typing import Optional +from typing import Optional, Literal from ratelimit import limits, RateLimitException, sleep_and_retry from backoff import on_exception, expo from time import sleep -from dataclasses import dataclass from wallabag2readwise.models import ( WallabagAnnotation, @@ -223,12 +222,19 @@ def post(self, endpoint: str, data: dict = {}) -> requests.Response: response.raise_for_status() return response - def create(self, url: str, saved_using: str = 'wallabag', tags: list[str] = []): + def create( + self, + url: str, + saved_using: str = 'wallabag', + tags: list[str] = [], + location: Literal['new', 'later', 'archive', 'feed'] = 'new', + ): _ = self.post( '/save/', { 'url': url, 'saved_using': saved_using, 'tags': tags, + 'location': location, }, ) diff --git a/wallabag2readwise/wallabag.py b/wallabag2readwise/wallabag.py index 73b4832..4cca5d1 100644 --- a/wallabag2readwise/wallabag.py +++ b/wallabag2readwise/wallabag.py @@ -74,6 +74,7 @@ def get_entries(self) -> Generator[WallabagEntry, None, None]: content=entry['content'], annotations=entry['annotations'], tags=[WallabagTag(**tag) for tag in entry['tags']], + archived=True if entry['is_archived'] == 1 else False, ) if page == data['pages']: