Compare commits

...

8 Commits

Author SHA1 Message Date
jeancf
969b6849b8 Other time representation 2023-06-28 18:34:42 +02:00
jeancf
f1b7247b3d Corrected one more float bug 2023-06-28 17:57:15 +02:00
jeancf
93f8e493db Fixed float timestamp bug 2023-06-28 17:46:00 +02:00
jeancf
156df6040c correct logging message 2023-06-28 16:29:32 +02:00
jeancf
b5f6405ceb Test further 2023-06-28 15:19:46 +02:00
jeancf
23d897f42c Small adjustment 2023-06-28 14:58:02 +02:00
jeancf
3732392dbf Longer wait to mitigate API error 422 2023-06-28 13:53:26 +02:00
jeancf
9e66475fe0 Set release date 2023-06-28 13:35:39 +02:00
2 changed files with 14 additions and 14 deletions

View File

@ -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

View File

@ -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)