ajout delay pour envoi différé

This commit is contained in:
cquest 2019-06-25 15:05:16 +02:00
parent 2a4f3cd3f7
commit 8c6c279c2b

View File

@ -9,7 +9,7 @@ from mastodon import Mastodon
import requests import requests
if len(sys.argv) < 4: if len(sys.argv) < 4:
print("Usage: python3 tootbot.py twitter_account mastodon_login mastodon_passwd mastodon_instance [max_days [footer_tags]]") # noqa print("Usage: python3 tootbot.py twitter_account mastodon_login mastodon_passwd mastodon_instance [max_days [footer_tags [delay]]]") # noqa
sys.exit(1) sys.exit(1)
# sqlite db to store processed tweets (and corresponding toots ids) # sqlite db to store processed tweets (and corresponding toots ids)
@ -33,6 +33,12 @@ if len(sys.argv) > 6:
else: else:
tags = None tags = None
if len(sys.argv) > 7:
delay = int(sys.argv[7])
else:
delay = 0
source = sys.argv[1] source = sys.argv[1]
mastodon = sys.argv[2] mastodon = sys.argv[2]
passwd = sys.argv[3] passwd = sys.argv[3]
@ -53,8 +59,8 @@ for t in reversed(d.entries):
dt = t.published_parsed dt = t.published_parsed
age = datetime.now()-datetime(dt.tm_year, dt.tm_mon, dt.tm_mday, age = datetime.now()-datetime(dt.tm_year, dt.tm_mon, dt.tm_mday,
dt.tm_hour, dt.tm_min, dt.tm_sec) dt.tm_hour, dt.tm_min, dt.tm_sec)
# process only unprocessed tweets less than 1 day old # process only unprocessed tweets less than 1 day old, after delay
if last is None and age < timedelta(days=days): if last is None and age < timedelta(days=days) and age > timedelta(days=delay):
if mastodon_api is None: if mastodon_api is None:
# Create application if it does not exist # Create application if it does not exist
if not os.path.isfile(instance+'.secret'): if not os.path.isfile(instance+'.secret'):