polar: move to top level, add page support

This commit is contained in:
Dima Gerasimov 2021-05-29 13:10:11 +01:00 committed by karlicoss
parent e8be20dcb5
commit 2a4bddea79
5 changed files with 19 additions and 17 deletions

View file

@ -246,7 +246,7 @@ Here's the (incomplete) list of the modules:
| [[https://github.com/karlicoss/HPI/tree/master/my/photos/main.py][=my.photos.main=]] | Photos and videos on your filesystem, their GPS and timestamps |
| [[https://github.com/karlicoss/HPI/tree/master/my/pinboard.py][=my.pinboard=]] | [[https://pinboard.in][Pinboard]] bookmarks |
| [[https://github.com/karlicoss/HPI/tree/master/my/pocket.py][=my.pocket=]] | [[https://getpocket.com][Pocket]] bookmarks and highlights |
| [[https://github.com/karlicoss/HPI/tree/master/my/reading/polar.py][=my.reading.polar=]] | [[https://github.com/burtonator/polar-bookshelf][Polar]] articles and highlights |
| [[https://github.com/karlicoss/HPI/tree/master/my/polar.py][=my.polar=]] | [[https://github.com/burtonator/polar-bookshelf][Polar]] articles and highlights |
| [[https://github.com/karlicoss/HPI/tree/master/my/reddit.py][=my.reddit=]] | Reddit data: saved items/comments/upvotes/etc. |
| [[https://github.com/karlicoss/HPI/tree/master/my/rescuetime.py][=my.rescuetime=]] | Rescuetime (phone activity tracking) data. |
| [[https://github.com/karlicoss/HPI/tree/master/my/roamresearch.py][=my.roamresearch=]] | [[https://roamresearch.com][Roam]] data |

View file

@ -23,7 +23,7 @@ If you have some issues with the setup, see [[file:SETUP.org::#troubleshooting][
- [[#mytwittertwint][my.twitter.twint]]
- [[#mytwitterarchive][my.twitter.archive]]
- [[#mylastfm][my.lastfm]]
- [[#myreadingpolar][my.reading.polar]]
- [[#mypolar][my.polar]]
- [[#myinstapaper][my.instapaper]]
- [[#mygithubgdpr][my.github.gdpr]]
- [[#mygithubghexport][my.github.ghexport]]
@ -79,7 +79,7 @@ modules = [
('twint' , 'my.twitter.twint' ),
('twitter_archive', 'my.twitter.archive' ),
('lastfm' , 'my.lastfm' ),
('polar' , 'my.reading.polar' ),
('polar' , 'my.polar' ),
('instapaper' , 'my.instapaper' ),
('github' , 'my.github.gdpr' ),
('github' , 'my.github.ghexport' ),
@ -197,7 +197,7 @@ for cls, p in modules:
"""
export_path: Paths
#+end_src
** [[file:../my/reading/polar.py][my.reading.polar]]
** [[file:../my/polar.py][my.polar]]
[[https://github.com/burtonator/polar-bookshelf][Polar]] articles and highlights

View file

@ -229,7 +229,7 @@ Polar doesn't require any setup as it accesses the highlights on your filesystem
You can try if it works with:
: python3 -c 'import my.reading.polar as polar; print(polar.get_entries())'
: python3 -c 'import my.polar as polar; print(polar.get_entries())'
** Google Takeout
If you have zip Google Takeout archives, you can use HPI to access it:
@ -307,11 +307,11 @@ It's understandable from the app developer's perspective, but it makes things fr
# todo hmm what if I could share deserialization with Polar app?
Here comes the HPI [[file:../my/reading/polar.py][polar module]]!
Here comes the HPI [[file:../my/polar.py][polar module]]!
: |💾 ~/.polar (raw JSON data) |
: ⇓⇓⇓
: HPI (my.reading.polar)
: HPI (my.polar)
: ⇓⇓⇓
: < python interface >

View file

@ -19,7 +19,7 @@ if user_config is None:
pass
from ..core import PathIsh
from .core import PathIsh
from dataclasses import dataclass
@dataclass
class polar(user_config):
@ -30,7 +30,7 @@ class polar(user_config):
defensive: bool = True # pass False if you want it to fail faster on errors (useful for debugging)
from ..core import make_config
from .core import make_config
config = make_config(polar)
# todo not sure where it keeps stuff on Windows?
@ -40,10 +40,10 @@ from datetime import datetime
from typing import List, Dict, Iterable, NamedTuple, Sequence, Optional
import json
from ..core import LazyLogger, Json
from ..core.common import isoparse
from ..error import Res, echain, sort_res_by
from ..core.konsume import wrap, Zoomable, Wdict
from .core import LazyLogger, Json
from .core.common import isoparse
from .error import Res, echain, sort_res_by
from .core.konsume import wrap, Zoomable, Wdict
logger = LazyLogger(__name__)
@ -63,6 +63,7 @@ class Highlight(NamedTuple):
selection: str
comments: Sequence[Comment]
tags: Sequence[str]
page: int # 1-indexed
color: Optional[str] = None
@ -122,7 +123,7 @@ class Loader:
# TODO want to ignore the whole subtree..
pi = meta['pageInfo'].zoom()
pi['num'].zoom()
page = pi['num'].zoom().value
if 'dimensions' in pi:
pi['dimensions'].consume_all()
@ -185,6 +186,7 @@ class Loader:
selection=text,
comments=tuple(comments),
tags=tuple(htags),
page=page,
color=color,
)
h.consume()
@ -228,7 +230,7 @@ class Loader:
def iter_entries() -> Iterable[Result]:
from ..core import get_files
from .core import get_files
for d in get_files(config.polar_dir, glob='*/state.json'):
loader = Loader(d)
try:

View file

@ -11,7 +11,7 @@ import pytest # type: ignore
def test_hpi(prepare: str) -> None:
from my.reading.polar import get_entries
from my.polar import get_entries
assert len(list(get_entries())) > 1
def test_orger(prepare: str, tmp_path: Path) -> None:
@ -45,7 +45,7 @@ def prepare(request):
import my.config
setattr(my.config, 'polar', user_config)
import my.reading.polar as polar
import my.polar as polar
reload(polar)
# TODO hmm... ok, need to document reload()
yield dotpolar