diff --git a/cron-sample.sh b/cron-sample.sh index 0e5a804..b38db5c 100644 --- a/cron-sample.sh +++ b/cron-sample.sh @@ -8,8 +8,10 @@ # 4- instance domain (https:// is automatically added) # 5- max age (in days) # 6- footer tags to add (optional) +# 7- delay (optional) +# 8- visibility unlisted (if 0 or unset visibility is public, if 1 visibility is unlisted) python3 tootbot.py geonym_fr geonym@amicale.net **password** test.amicale.net python3 tootbot.py cq94 cquest@amicale.net **password** test.amicale.net -python3 tootbot.py https://www.data.gouv.fr/fr/datasets/recent.atom cquest+opendata@amicale.net **password** amicale.net 2 "#dataset #opendata #datagouvfr" +python3 tootbot.py https://www.data.gouv.fr/fr/datasets/recent.atom cquest+opendata@amicale.net **password** amicale.net 2 "#dataset #opendata #datagouvfr" 0 1 diff --git a/tootbot.py b/tootbot.py index a91e021..45d4059 100755 --- a/tootbot.py +++ b/tootbot.py @@ -37,7 +37,7 @@ def unredir(redir): if len(sys.argv) < 4: - print("Usage: python3 tootbot.py twitter_account mastodon_login mastodon_passwd mastodon_instance [max_days [footer_tags [delay]]]") # noqa + print("Usage: python3 tootbot.py twitter_account mastodon_login mastodon_passwd mastodon_instance [max_days [footer_tags [delay [unlisted]]]]") # noqa sys.exit(1) if len(sys.argv) > 4: @@ -60,6 +60,11 @@ def unredir(redir): else: delay = 0 +if len(sys.argv) > 8 and (int(sys.argv[8]) == 1): + mastodon_visibility = "unlisted" +else: + mastodon_visibility = "public" + source = sys.argv[1] mastodon = sys.argv[2] passwd = sys.argv[3] @@ -126,10 +131,17 @@ def unredir(redir): db.execute('SELECT * FROM tweets WHERE tweet = ? AND twitter = ? and mastodon = ? and instance = ?', (id, source, mastodon, instance)) # noqa last = db.fetchone() dt = t.published_parsed - age = datetime.now()-datetime(dt.tm_year, dt.tm_mon, dt.tm_mday, + # if the date of a feed is invalid, the parser might return a NoneType + if dt is None: + print("Couldn't parse feed date, ignoring date...") + process = last is None + else: + age = datetime.now()-datetime(dt.tm_year, dt.tm_mon, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec) - # process only unprocessed tweets less than 1 day old, after delay - if last is None and age < timedelta(days=days) and age > timedelta(days=delay): + # process only unprocessed tweets less than 1 day old, after delay + process = last is None and age < timedelta(days=days) and age > timedelta(days=delay) + + if process: c = t.title if twitter and t.author.lower() != ('(@%s)' % twitter).lower(): c = ("RT https://twitter.com/%s\n" % t.author[2:-1]) + c @@ -196,7 +208,7 @@ def unredir(redir): in_reply_to_id=None, media_ids=toot_media, sensitive=False, - visibility='public', + visibility=mastodon_visibility, spoiler_text=None) if "id" in toot: db.execute("INSERT INTO tweets VALUES ( ? , ? , ? , ? , ? )",