diff --git a/tootbot.py b/tootbot.py index 15513cecb68c9fae147bb09c7e7b1d750c186e99..626d14f1675dcc42f5b16d685765e2ea1cbaac28 100755 --- a/tootbot.py +++ b/tootbot.py @@ -14,10 +14,13 @@ auth_session = auth_file+'.session' mastodon_api = None # Set to 1 to get some messages, 0 for error messages only -debug=1 +debug=0 # Posting delay (s), wait between mastodon posts, reduces the "burst" effect on timoeline, and instance workload if you hit rate limiters -posting_delay=1 +posting_delay=3 + +# Post only this much tweets per cycle +max_tweets=2 # URL substrings dedicated to source image hosting twitter_pics_hosting="https://pbs.twitimg.com/" @@ -92,14 +95,16 @@ if debug: print("Processing", end='') # Cut the source URL to avoid reposts when looking up the DB source=source.split("/search/")[0] +nb_tweets=0 for tweet in reversed(d.entries): # check if this tweet has been processed db.execute('SELECT * FROM tweets WHERE tweet = ? AND twitter = ? and mastodon = ? and instance = ?', (tweet.id, source, mastodon_account, instance)) # noqa last = db.fetchone() dt = tweet.published_parsed 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 x day old, after delay, and at most max_tweets + if last is None and age < timedelta(days=days) and age > timedelta(days=delay) and nb_tweets < max_tweets: + nb_tweets = nb_tweets + 1 if "token" in auth_type and mastodon_api is None: try: mastodon_api = Mastodon(client_id=app_client_id, client_secret=app_client_secret, access_token=app_access_token, api_base_url='https://'+instance) @@ -187,7 +192,7 @@ for tweet in reversed(d.entries): if toot_media is not None: try: - toot = mastodon_api.status_post(toot_body, in_reply_to_id=None, media_ids=toot_media, sensitive=False, visibility='public', spoiler_text=None) + toot = mastodon_api.status_post(toot_body, in_reply_to_id=None, media_ids=toot_media, sensitive=False, visibility='unlisted', spoiler_text=None) if "id" in toot: db.execute("INSERT INTO tweets VALUES ( ? , ? , ? , ? , ? )",(tweet.id, toot["id"], source, mastodon_account, instance)) sql.commit()