Skip to content

Commit

Permalink
fix(reader): support archived location
Browse files Browse the repository at this point in the history
  • Loading branch information
rwxd committed Feb 23, 2023
1 parent ec275ae commit 5d839f0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion wallabag2readwise/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions wallabag2readwise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class WallabagEntry:
url: str
hashed_url: str
annotations: list
archived: bool
tags: list[WallabagTag]


Expand Down
12 changes: 9 additions & 3 deletions wallabag2readwise/readwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
)
1 change: 1 addition & 0 deletions wallabag2readwise/wallabag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down

0 comments on commit 5d839f0

Please sign in to comment.