Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cron-sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] **password** test.amicale.net
python3 tootbot.py cq94 [email protected] **password** test.amicale.net

python3 tootbot.py https://www.data.gouv.fr/fr/datasets/recent.atom [email protected] **password** amicale.net 2 "#dataset #opendata #datagouvfr"
python3 tootbot.py https://www.data.gouv.fr/fr/datasets/recent.atom [email protected] **password** amicale.net 2 "#dataset #opendata #datagouvfr" 0 1
22 changes: 17 additions & 5 deletions tootbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ( ? , ? , ? , ? , ? )",
Expand Down