1
+ # TODO: move all "typer" usage to feedbin.adapters.cli
2
+
1
3
import os
2
4
from typing import Annotated
3
5
4
6
import rich
5
7
import typer
6
8
7
- from feedbin .api import NotFoundError , UnexpectedError
8
- from feedbin .api .subscriptions import FeedOption , MultipleChoicesError , Subscription , create_subscription
9
- from utils .cli import DryRun
10
- from utils .logs import log
9
+ from common .cli import DryRun
10
+ from common .logs import log
11
+ from feedbin .adapters .api import NotFoundError , UnexpectedError
12
+ from feedbin .adapters .api .entries import get_feed_entries
13
+ from feedbin .adapters .api .subscriptions import FeedOption , MultipleChoicesError , Subscription , create_subscription
14
+ from feedbin .application .mark_entries_unread import mark_entries_unread
11
15
12
16
app = typer .Typer (no_args_is_help = True )
13
17
@@ -55,7 +59,7 @@ def subscribe_to_feed(url: str) -> Subscription:
55
59
Unread = Annotated [bool , typer .Option ("--unread" , "-u" , help = "Mark backlog unread" )]
56
60
57
61
58
- def main (url : str , mark_backlog_unread : Unread = False , dry_run : DryRun = False ) -> None :
62
+ def add_subscription (url : str , mark_backlog_unread : Unread = False , dry_run : DryRun = False ) -> None :
59
63
dry_run = os .getenv ("DRY_RUN" ) == "true" or dry_run
60
64
61
65
typer .confirm (f"π Subscribe to '{ url } '?" , abort = True )
@@ -67,13 +71,21 @@ def main(url: str, mark_backlog_unread: Unread = False, dry_run: DryRun = False)
67
71
new_subscription = subscribe_to_feed (url )
68
72
log .debug (f"π new_subscription: { new_subscription } " )
69
73
70
- mark_unread = typer .confirm ("π Mark backlog unread?" , default = mark_backlog_unread )
74
+ mark_backlog_unread = typer .confirm ("π Mark backlog unread?" , default = mark_backlog_unread )
71
75
72
- if not mark_unread :
76
+ if not mark_backlog_unread :
73
77
rich .print ("π You're all set!" )
74
78
typer .Exit ()
75
79
76
- log .info ("π Marking backlog as unread" )
80
+ log .info ("π Getting all entries" )
81
+ entries = get_feed_entries (new_subscription .feed_id )
82
+ log .debug (f"π entries: { entries } " )
83
+
84
+ entry_ids = [entry .id for entry in entries ]
85
+ log .debug (f"π entry_ids: { entry_ids } " )
86
+
87
+ log .info ("π Marking all entries as unread" )
88
+ mark_entries_unread (entry_ids )
77
89
# TODO: get all entry ids for this subscription via get_feed_entries
78
90
# TODO: mark all entries as unread via https://github.com/feedbin/feedbin-api/blob/master/content/unread-entries.md#create-unread-entries-mark-as-unread
79
91
0 commit comments