# HG changeset patch # User Ludovic Chabant # Date 1684685900 25200 # Node ID 8e8541ef85b7912972c74d8043e2c54e592cb3b7 # Parent 7965adc14569e3cbfb89859457bbf163fa542c37 Add --until argument to the process command Also fix missing requirement/dependency for dateparser diff -r 7965adc14569 -r 8e8541ef85b7 Pipfile --- a/Pipfile Wed May 10 16:11:11 2023 -0700 +++ b/Pipfile Sun May 21 09:18:20 2023 -0700 @@ -11,6 +11,7 @@ "mastodon.py" = "*" coloredlogs = "*" "mf2util" = "*" +dateparser = "*" python-dateutil = "*" python-twitter = "*" ronkyuu = "*" diff -r 7965adc14569 -r 8e8541ef85b7 silorider/commands/process.py --- a/silorider/commands/process.py Wed May 10 16:11:11 2023 -0700 +++ b/silorider/commands/process.py Sun May 21 09:18:20 2023 -0700 @@ -1,4 +1,5 @@ import logging +import dateparser from .utils import get_named_silos, get_named_urls from ..silos.base import SiloPostingContext from ..parse import parse_url @@ -38,10 +39,11 @@ self.postProcess() def preProcess(self): - # Pre-parse the "since" date/time. + # Pre-parse the "since" and "until" dates/times. if self.ctx.args.since: - import dateparser self.ctx.args.since = dateparser.parse(self.ctx.args.since) + if self.ctx.args.until: + self.ctx.args.until = dateparser.parse(self.ctx.args.until) for silo in self.silos: silo.onPostStart(self.ctx) @@ -63,9 +65,10 @@ postctx = SiloPostingContext(self.ctx) no_cache = self.ctx.args.no_cache only_since = self.ctx.args.since + only_until = self.ctx.args.until logger.debug("Processing entry: %s" % entry_url) for silo in self.silos: - if only_since: + if only_since or only_until: entry_dt = entry.get('published') if not entry_dt: logger.warning( @@ -75,14 +78,20 @@ # Strip entry datetime's time-zone information if we # don't have a time-zone info from the command line. - if not only_since.tzinfo: + if ((only_since and not only_since.tzinfo) or + (only_until and not only_until.tzinfo)): entry_dt = entry_dt.replace(tzinfo=None) - if entry_dt < only_since: + if only_since and entry_dt < only_since: logger.info( "Skipping entry older than specified date/time " "for %s: %s" % (silo.name, entry_url)) continue + if only_until and entry_dt > only_until: + logger.info( + "Skipping entry newer than specified date/time " + "for %s: %s" % (silo.name, entry_url)) + continue if not no_cache and self.ctx.cache.wasPosted(silo.name, entry_url): logger.debug("Skipping already posted entry on %s: %s" % diff -r 7965adc14569 -r 8e8541ef85b7 silorider/main.py --- a/silorider/main.py Wed May 10 16:11:11 2023 -0700 +++ b/silorider/main.py Sun May 21 09:18:20 2023 -0700 @@ -61,6 +61,9 @@ '--since', help="Post entries since the specified date/time only.") parser.add_argument( + '--until', + help="Post entries until the specified date/time only.") + parser.add_argument( '--dry-run', action='store_true', help="Only report what would be posted, but don't post anything.")