-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#27): add select command to select between articles
Fixes #27
- Loading branch information
1 parent
8d4a213
commit 885bad1
Showing
17 changed files
with
177 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import questionary | ||
from iterpy._iter import Iter | ||
|
||
from ..document_providers.Document import Document | ||
|
||
|
||
def select_documents(docs: Iter[Document]) -> Iter[Document]: | ||
doc_titles = docs.map(lambda d: d.title).to_list() | ||
selected_doc_names = questionary.checkbox( | ||
message="Select documents", choices=doc_titles | ||
).ask() | ||
return docs.filter(lambda d: d.title in selected_doc_names) |
25 changes: 25 additions & 0 deletions
25
memorymarker/document_providers/ContextualizedHighlight.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
import datetime as dt | ||
|
||
|
||
class ContextualizedHighlight(BaseModel): | ||
source_doc_title: str | ||
source_doc_uri: str | ||
|
||
prefix: str | None | ||
highlighted_text: str | ||
suffix: str | None | ||
|
||
source_highlight_uri: str | None = None | ||
updated_at: dt.datetime | ||
|
||
@property | ||
def context(self) -> str: | ||
context = "" | ||
context += self.prefix or "" | ||
context += self.highlighted_text | ||
context += self.suffix or "" | ||
|
||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Any, Mapping, Sequence | ||
|
||
from iterpy._iter import Iter | ||
from pydantic import BaseModel | ||
|
||
from .ContextualizedHighlight import ContextualizedHighlight | ||
|
||
|
||
class Document(BaseModel): | ||
title: str | ||
uri: str | ||
slug: str | ||
highlights: Sequence[Mapping[str, Any]] | ||
|
||
def _parse_highlight(self, highlight: Mapping[str, str]) -> ContextualizedHighlight: | ||
return ContextualizedHighlight( | ||
source_doc_title=self.title, | ||
source_doc_uri=self.uri, | ||
highlighted_text=highlight["quote"], | ||
prefix=highlight["prefix"], | ||
suffix=highlight["suffix"], | ||
updated_at=highlight["updatedAt"], # type: ignore | ||
source_highlight_uri=f"https://omnivore.app/me/{self.slug}#{highlight["id"]}", | ||
) | ||
|
||
def get_highlights(self) -> Iter[ContextualizedHighlight]: | ||
return Iter(self.highlights).map(self._parse_highlight) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import datetime as dt | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import Protocol, Sequence | ||
|
||
from iterpy._iter import Iter | ||
|
||
from memorymarker.document_providers.ContextualizedHighlight import ( | ||
ContextualizedHighlight, | ||
) | ||
|
||
from .Document import Document | ||
|
||
|
||
@dataclass(frozen=True) | ||
class OrphanHighlight: | ||
highlight: str | ||
uri: str | ||
title: str | ||
|
||
|
||
class DocumentProvider(Protocol): | ||
def get_documents(self) -> Iter[Document]: | ||
... | ||
|
||
|
||
class HighlightManager(Protocol): | ||
timestamp_file: Path | ||
source: DocumentProvider | ||
|
||
def get_highlights_since_update( | ||
self, date: dt.datetime | ||
) -> Sequence[ContextualizedHighlight]: | ||
... |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...light_providers/hydrator/test_hydrator.py → ...ument_providers/hydrator/test_hydrator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
from dataclasses import dataclass | ||
from typing import Mapping | ||
|
||
from iterpy._iter import Iter | ||
from omnivoreql import OmnivoreQL | ||
|
||
from memorymarker.document_providers.Document import Document | ||
|
||
from .base import DocumentProvider | ||
|
||
|
||
@dataclass | ||
class Omnivore(DocumentProvider): | ||
def __post_init__(self): | ||
omnivore_api_key = os.getenv("OMNIVORE_API_KEY") | ||
if not omnivore_api_key: | ||
raise ValueError("OMNIVORE_API_KEY environment variable not set") | ||
self.client = OmnivoreQL(omnivore_api_key) | ||
|
||
def _parse_doc(self, document: Mapping[str, str]) -> Document: | ||
return Document( | ||
title=document["title"], | ||
uri=document["url"], | ||
highlights=document["highlights"], # type: ignore | ||
slug=document["slug"], | ||
) | ||
|
||
def get_documents(self) -> Iter[Document]: | ||
documents = ( | ||
Iter(self.client.get_articles(limit=1000)["search"]["edges"]) | ||
.map(lambda a: a["node"]) | ||
.map(self._parse_doc) | ||
.flatten() | ||
) | ||
return documents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.