mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-02-24 17:08:42 +00:00
Compare commits
8 Commits
191c23074d
...
969b6849b8
Author | SHA1 | Date | |
---|---|---|---|
|
969b6849b8 | ||
|
f1b7247b3d | ||
|
93f8e493db | ||
|
156df6040c | ||
|
b5f6405ceb | ||
|
23d897f42c | ||
|
3732392dbf | ||
|
9e66475fe0 |
@ -3,7 +3,7 @@
|
|||||||
Twoot is a python script that mirrors tweets from a twitter account to a Mastodon account.
|
Twoot is a python script that mirrors tweets from a twitter account to a Mastodon account.
|
||||||
It is simple to set-up on a local machine, configurable and feature-rich.
|
It is simple to set-up on a local machine, configurable and feature-rich.
|
||||||
|
|
||||||
**19 JUN 2023** VERSION 4.0
|
**28 JUN 2023** VERSION 4.0
|
||||||
|
|
||||||
* Added option to update avatar and banner pictures on profile if changed on Twitter
|
* Added option to update avatar and banner pictures on profile if changed on Twitter
|
||||||
* Tweaked list of nitter instances
|
* Tweaked list of nitter instances
|
||||||
|
26
twoot.py
26
twoot.py
@ -796,8 +796,8 @@ def main(argv):
|
|||||||
logging.info(' tweet_delay : ' + str(TOML['options']['tweet_delay']))
|
logging.info(' tweet_delay : ' + str(TOML['options']['tweet_delay']))
|
||||||
logging.info(' toot_cap : ' + str(TOML['options']['toot_cap']))
|
logging.info(' toot_cap : ' + str(TOML['options']['toot_cap']))
|
||||||
logging.info(' subst_twitter : ' + str(TOML['options']['subst_twitter']))
|
logging.info(' subst_twitter : ' + str(TOML['options']['subst_twitter']))
|
||||||
logging.info(' subst_twitter : ' + str(TOML['options']['subst_youtube']))
|
logging.info(' subst_youtube : ' + str(TOML['options']['subst_youtube']))
|
||||||
logging.info(' subst_twitter : ' + str(TOML['options']['subst_reddit']))
|
logging.info(' subst_reddit : ' + str(TOML['options']['subst_reddit']))
|
||||||
logging.info(' log_level : ' + str(TOML['options']['log_level']))
|
logging.info(' log_level : ' + str(TOML['options']['log_level']))
|
||||||
logging.info(' log_days : ' + str(TOML['options']['log_days']))
|
logging.info(' log_days : ' + str(TOML['options']['log_days']))
|
||||||
|
|
||||||
@ -887,13 +887,13 @@ def main(argv):
|
|||||||
# Extract time stamp
|
# Extract time stamp
|
||||||
time_string = status.find('span', class_='tweet-date').a.get('title')
|
time_string = status.find('span', class_='tweet-date').a.get('title')
|
||||||
try:
|
try:
|
||||||
timestamp = datetime.strptime(time_string, '%d/%m/%Y, %H:%M:%S').timestamp()
|
timestamp = datetime.strptime(time_string, '%d/%m/%Y, %H:%M:%S')
|
||||||
except:
|
except:
|
||||||
# Dec 21, 2021 · 12:00 PM UTC
|
# Dec 21, 2021 · 12:00 PM UTC
|
||||||
timestamp = datetime.strptime(time_string, '%b %d, %Y · %I:%M %p %Z').timestamp()
|
timestamp = datetime.strptime(time_string, '%b %d, %Y · %I:%M %p %Z')
|
||||||
|
|
||||||
# Check if time is within acceptable range
|
# Check if time is within acceptable range
|
||||||
if not is_time_valid(timestamp):
|
if not is_time_valid(timestamp.timestamp()):
|
||||||
out_date_cnt += 1
|
out_date_cnt += 1
|
||||||
logging.debug("Tweet outside valid time range, skipping")
|
logging.debug("Tweet outside valid time range, skipping")
|
||||||
continue
|
continue
|
||||||
@ -976,13 +976,13 @@ def main(argv):
|
|||||||
# Add footer with link to original tweet
|
# Add footer with link to original tweet
|
||||||
if TOML['options']['remove_original_tweet_ref'] is False:
|
if TOML['options']['remove_original_tweet_ref'] is False:
|
||||||
if TOML['options']['footer'] != '':
|
if TOML['options']['footer'] != '':
|
||||||
tweet_text += '\nOriginal tweet : ' + substitute_source(full_status_url)
|
tweet_text += '\nOriginal tweet: ' + substitute_source(full_status_url)
|
||||||
else:
|
else:
|
||||||
tweet_text += '\n\nOriginal tweet : ' + substitute_source(full_status_url)
|
tweet_text += '\n\nOriginal tweet: ' + substitute_source(full_status_url)
|
||||||
|
|
||||||
# Check what timestamp would look like
|
# Check what timestamp would look like
|
||||||
logging.debug("TEST TIMESTAMP")
|
logging.debug("TEST TIMESTAMP " + str(time_string))
|
||||||
logging.debug(tweet_text + ' ' + time_string)
|
logging.debug(tweet_text + ' (' + datetime.strftime(timestamp, '%x %X') + ')')
|
||||||
|
|
||||||
# If no media was specifically added in the tweet, try to get the first picture
|
# If no media was specifically added in the tweet, try to get the first picture
|
||||||
# with "twitter:image" meta tag in first linked page in tweet text
|
# with "twitter:image" meta tag in first linked page in tweet text
|
||||||
@ -1024,7 +1024,7 @@ def main(argv):
|
|||||||
tweet = {
|
tweet = {
|
||||||
"author": author,
|
"author": author,
|
||||||
"author_account": author_account,
|
"author_account": author_account,
|
||||||
"timestamp": timestamp,
|
"timestamp": timestamp.timestamp(),
|
||||||
"tweet_id": tweet_id,
|
"tweet_id": tweet_id,
|
||||||
"tweet_text": tweet_text,
|
"tweet_text": tweet_text,
|
||||||
"video": video_file,
|
"video": video_file,
|
||||||
@ -1107,9 +1107,9 @@ def main(argv):
|
|||||||
except MastodonAPIError:
|
except MastodonAPIError:
|
||||||
# Assuming this is an:
|
# Assuming this is an:
|
||||||
# ERROR ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Cannot attach files that have not finished processing. Try again in a moment!')
|
# ERROR ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Cannot attach files that have not finished processing. Try again in a moment!')
|
||||||
logging.warning('Mastodon API Error 422: Cannot attach files that have not finished processing. Waiting 15 seconds and retrying.')
|
logging.warning('Mastodon API Error 422: Cannot attach files that have not finished processing. Waiting 60 seconds and retrying.')
|
||||||
# Wait 15 seconds
|
# Wait 60 seconds
|
||||||
time.sleep(15)
|
time.sleep(60)
|
||||||
# retry posting
|
# retry posting
|
||||||
try:
|
try:
|
||||||
toot = mastodon.status_post(tweet['tweet_text'], media_ids=media_ids)
|
toot = mastodon.status_post(tweet['tweet_text'], media_ids=media_ids)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user