def get_fieldnames(cls):
return cls.__fields__.keys()
+ def update(self, key, val):
+ self.__setattr__(key, val)
+
# TODO: What if there's a pipe in one of the fields?
def to_str(self, delimiter: str ='|'):
return delimiter.join([str(v) for v in self.__dict__.values()])
entry_subparsers = entry_parser.add_subparsers(dest='entry_command', help='Dispatches entry commands.')
entry_show_parser = entry_subparsers.add_parser('show', parents=[label_parser], help='Show entries.')
entry_show_parser.set_defaults(func=handle_entry_show)
- entry_update_parser = entry_subparsers.add_parser('update', help='Update entry data.')
+ entry_update_parser = entry_subparsers.add_parser('update', parents=[label_parser], help='update entry data.')
entry_update_parser.set_defaults(func=handle_entry_update)
+ entry_update_parser.add_argument('--update', dest="updates", nargs="*", help="Update values as key=value pairs")
+
# Feed subcommand
feed_parser = subparsers.add_parser('feed', help='Dispatches commands that operate on a table of feeds.')
elist.to_stdout(show_header=True)
def handle_entry_update(args):
- elist=EntryList()
- feedlist=FeedList.from_csv(FEED_LIST)
- for flitem in feedlist:
- elist += flitem.to_feed().to_entrylist()
- print(f"Updating from [{str(flitem)}]")
+ if not ENTRY_LIST.exists():
+ elist=EntryList()
+ else:
+ elist = EntryList.from_csv(ENTRY_LIST)
+
+ if args.updates:
+ sublist = elist.select(lambda e: e.label in args.label)
+ for u in args.updates:
+ key, val = u.split('=')
+ for e in elist:
+ if e in sublist:
+ e.update(key,val)
+ else:
+ feedlist=FeedList.from_csv(FEED_LIST)
+ for flitem in feedlist:
+ elist += flitem.to_feed().to_entrylist()
+ print(f"Updating from [{str(flitem)}]")
elist.to_csv(ENTRY_LIST)
def handle_feed_show(args):
from nom.main import cli, dispatch
-
+from nom.base import NomListItem
def argtest(argstr):
""" Asserts that the CLI entry points don't raise errors. """
def test_nom_entry_update():
argtest('entry update')
+
+def test_nom_entry_update_val():
+ NomListItem.update = print("Don't really update") #This actually works, lol
+ argv='entry update 1 --update url=https://path/to/new/url'.split(' ')
+ args = cli().parse_args(argv)
+ assert True