Mercurial > silorider
changeset 41:1db1890edcf5
Change populate command's 'until' argument to be exclusive and support time
The argument can now specify a time within the day, but this forces the
argument to now be exclusive. So if only a date is provided (no time),
you need to enter the next day, i.e. the first day to *not* be included.
This makes the argument effectively exclusive.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 20 Aug 2023 11:14:31 -0700 |
parents | c5f73ebb43a5 |
children | 67fde62e3862 |
files | silorider/commands/utils.py silorider/main.py tests/test_commands_populate.py |
diffstat | 3 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/silorider/commands/utils.py Sun May 21 09:42:11 2023 -0700 +++ b/silorider/commands/utils.py Sun Aug 20 11:14:31 2023 -0700 @@ -1,4 +1,5 @@ import logging +import datetime from ..parse import parse_url @@ -39,8 +40,9 @@ until_dt = None if ctx.args.until: - until_dt = dateutil.parser.parse(ctx.args.until).date() + until_dt = dateutil.parser.parse(ctx.args.until) logger.debug("Populating cache until: %s" % until_dt) + until_dt = until_dt.timestamp() for url in urls: logger.info("Caching entries from %s" % url) @@ -71,7 +73,10 @@ if isinstance(entry_published, list): entry_published = entry_published[0] - if entry_published and entry_published.date() > until_dt: + if entry_published and entry_published.timestamp() > until_dt: + logger.debug( + "Skipping entry because it's later than the 'until' date: %s" % + entry_published) continue for silo in silos:
--- a/silorider/main.py Sun May 21 09:42:11 2023 -0700 +++ b/silorider/main.py Sun Aug 20 11:14:31 2023 -0700 @@ -85,7 +85,7 @@ help="Only populate the given silo(s).") parser.add_argument( '--until', - help="The date until which to populate the cache (included).") + help="The date until which to populate the cache (excluded).") parser.add_argument( '--dry-run', action='store_true',
--- a/tests/test_commands_populate.py Sun May 21 09:42:11 2023 -0700 +++ b/tests/test_commands_populate.py Sun Aug 20 11:14:31 2023 -0700 @@ -44,7 +44,7 @@ feed = cli.createTempFeed(feed2) cli.appendSiloConfig('test', 'print', items='name') cli.setFeedConfig('feed', feed) - ctx, _ = cli.run('populate', '-s', 'test', '--until', '2018-01-08') + ctx, _ = cli.run('populate', '-s', 'test', '--until', '2018-01-08 9AM') assert ctx.cache.wasPosted('test', 'https://example.org/first-article') assert ctx.cache.wasPosted('test', 'https://example.org/second-article') assert not ctx.cache.wasPosted('test', 'https://example.org/third-article')