From dc1ad8208093d288a3fc1f4e40ed8a85475411bf Mon Sep 17 00:00:00 2001 From: jeancf Date: Tue, 11 Jul 2023 13:15:43 +0200 Subject: [PATCH] Added timezone logic --- twoot.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/twoot.py b/twoot.py index 0bd8e56..e7c716b 100755 --- a/twoot.py +++ b/twoot.py @@ -92,6 +92,7 @@ def build_config(args): 'remove_trackers_from_urls': False, 'footer': "", 'tweet_time_format': "", + 'tweet_timezone': "", 'remove_original_tweet_ref': False, 'tweet_max_age': float(1), 'tweet_delay': float(0), @@ -792,6 +793,7 @@ def main(argv): logging.info(' remove_trackers_from_urls: ' + str(TOML['options']['remove_trackers_from_urls'])) logging.info(' footer : ' + TOML['options']['footer']) logging.info(' tweet_time_format : ' + TOML['options']['tweet_time_format']) + logging.info(' tweet_timezone : ' + TOML['options']['tweet_timezone']) logging.info(' remove_original_tweet_ref: ' + str(TOML['options']['remove_original_tweet_ref'])) logging.info(' update_profile : ' + str(TOML['options']['update_profile'])) logging.info(' tweet_max_age : ' + str(TOML['options']['tweet_max_age'])) @@ -984,7 +986,19 @@ def main(argv): # Add timestamp to the "Original Tweet" line if TOML['options']['tweet_time_format'] != "": - tweet_text += ' ' + datetime.strftime(timestamp, TOML['options']['tweet_time_format']) + timestamp_display = timestamp + # Adjust timezone + import pytz + if TOML['options']['tweet_timezone'] != "": + timezone_display = pytz.timezone(TOML['options']['tweet_timezone']) + else: # Use local timezone by default + timezone_display = datetime.now().astimezone().tzinfo + logging.debug("Timestamp UTC " + str(timestamp)) + logging.debug("Timezone to use" + str(timezone_display)) + timestamp_display = pytz.utc.localize(timestamp).astimezone(timezone_display) + logging.debug("Timestamp converted " + str(timestamp_display)) + + tweet_text += ' (' + datetime.strftime(timestamp_display, TOML['options']['tweet_time_format']) + ')' # 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