From: Kyle Bowman Date: Tue, 21 Jan 2025 04:10:09 +0000 (-0500) Subject: add numbering that persists w/ line items X-Git-Url: https://git.rocketbowman.com/?a=commitdiff_plain;h=d4fab788355d2718dd8bebbcb7e718d59b63a033;p=nom.git add numbering that persists w/ line items --- diff --git a/src/nom/base.py b/src/nom/base.py index fbd4caa..77a89ef 100644 --- a/src/nom/base.py +++ b/src/nom/base.py @@ -11,6 +11,7 @@ Predicate = Callable[..., bool] class NomListItem(BaseModel): + label: Optional[int] = -1 @abstractmethod def __hash__(self): @@ -41,6 +42,11 @@ class NomList(set): else: super().__init__(elements) + # Number items and persist via label attribute + for i, item in enumerate(self, start=1): + if not item.label: + item.__setattr__('label',i) + def __add__(self, other): return self.__class__(self.union(other)) diff --git a/src/nom/cli.py b/src/nom/cli.py index c39736d..a3e7d1a 100644 --- a/src/nom/cli.py +++ b/src/nom/cli.py @@ -14,5 +14,6 @@ def cli(): feed_parser = subparsers.add_parser('feed', help='Feed related commands') feed_subparsers = feed_parser.add_subparsers(dest='feed_command', help='Feed sub-command help') feed_update_parser = feed_subparsers.add_parser('update', help='Update feed') + feed_update_parser = feed_subparsers.add_parser('show', help='Show feeds') return parser diff --git a/src/nom/main.py b/src/nom/main.py index 26850f7..de5fbe0 100644 --- a/src/nom/main.py +++ b/src/nom/main.py @@ -24,6 +24,8 @@ def main(args=['nom'].append(sys.argv)): elist.to_stdout() elif args.command == "feed" and args.feed_command == "update": feedlist.fetch_feeds(FEED_CACHE) + elif args.command == "feed" and args.feed_command == "show": + feedlist.to_stdout() else: raise NomError("That option is not yet supported.") diff --git a/tests/data/entry_multi.csv b/tests/data/entry_multi.csv index bb54fee..e369cf2 100644 --- a/tests/data/entry_multi.csv +++ b/tests/data/entry_multi.csv @@ -1,3 +1,3 @@ -title|url|date|feed_url|feed_alias|viewed|summary -Entry One|https://path/to/entry2.html|date|https://path/to/feed.atom|feed1|False| -Entry Two|https://path/to/entry3.html|date|https://path/to/feed.atom|feed2|True| +label|title|url|date|feed_url|feed_alias|viewed|summary +1|Entry One|https://path/to/entry2.html|date|https://path/to/feed.atom|feed1|False| +2|Entry Two|https://path/to/entry3.html|date|https://path/to/feed.atom|feed2|True| diff --git a/tests/test_cli.py b/tests/test_cli.py index 7c1c086..7e7036b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -7,4 +7,8 @@ def test_nom_entry_show(): def test_nom_feed_update(): main(args='feed update'.split(' ')) + assert True + +def test_nom_feed_show(): + main(args='feed show'.split(' ')) assert True \ No newline at end of file diff --git a/tests/test_entry.py b/tests/test_entry.py index df215b3..30b307f 100644 --- a/tests/test_entry.py +++ b/tests/test_entry.py @@ -44,3 +44,8 @@ def test_elist_addition(elist_multi, elist_single): def test_elist_select(elist_multi): viewed = elist_multi.select(lambda e: e.viewed) assert len(viewed) < len(elist_multi) + +def test_elist_select_entry(elist_multi): + second = elist_multi.select(lambda e: e.label == 2).pop() + assert second.label == 2 + assert second.title == "Entry Two"