Fix: Posts published while feediverse is running are not tooted.

Fix race-condition: If a post was published within the short period of
time between fetching the RSS feed and saving the config-file, this
post was not tooted. This was caused by the timestamp in the
config-file having been the time when the file was written, not when
the feed was fetched.

I (hopefully) fixed this by storing the latest post's timestamp in the
config file. This still might cause the same issue if several feeds
are checked using the same config file.
This commit is contained in:
Hartmut Goebel
2020-09-25 21:08:36 +02:00
parent 7c7f1c049c
commit 2748ac0da6

View File

@ -54,10 +54,12 @@ def main():
access_token=config['access_token'] access_token=config['access_token']
) )
newest_post = config['updated']
for feed in config['feeds']: for feed in config['feeds']:
for entry in get_feed(feed['url'], config['updated'], for entry in get_feed(feed['url'], config['updated'],
config['include_images'], config['include_images'],
generator=feed.get('generator')): generator=feed.get('generator')):
newest_post = max(newest_post, entry['updated'])
if args.verbose: if args.verbose:
try: try:
print(entry) print(entry)
@ -78,6 +80,8 @@ def main():
entry.pop("images", None) entry.pop("images", None)
masto.status_post(feed['template'].format(**entry)[:49999999999], masto.status_post(feed['template'].format(**entry)[:49999999999],
media_ids=media_ids) media_ids=media_ids)
config['updated'] = newest_post.isoformat()
if args.dry_run: if args.dry_run:
print("trial run, not saving the config") print("trial run, not saving the config")
else: else:
@ -86,10 +90,8 @@ def main():
save_config(config, config_file) save_config(config, config_file)
def save_config(config, config_file, toot_old_posts=False): def save_config(config, config_file):
copy = dict(config) copy = dict(config)
if not toot_old_posts:
copy['updated'] = datetime.now(tz=timezone.utc).isoformat()
with open(config_file, 'w') as fh: with open(config_file, 'w') as fh:
fh.write(yaml.dump(copy, default_flow_style=False)) fh.write(yaml.dump(copy, default_flow_style=False))
@ -253,7 +255,9 @@ def setup(config_file):
{'url': feed_url, 'template': '{title} {url}'} {'url': feed_url, 'template': '{title} {url}'}
] ]
} }
save_config(config, config_file, old_posts) if not toot_old_posts:
config['updated'] = datetime.now(tz=timezone.utc).isoformat()
save_config(config, config_file)
print("") print("")
print("Your feediverse configuration has been saved to {}".format(config_file)) print("Your feediverse configuration has been saved to {}".format(config_file))
print("Add a line line this to your crontab to check every 15 minutes:") print("Add a line line this to your crontab to check every 15 minutes:")