Added timezone logic

This commit is contained in:
jeancf 2023-07-11 13:15:43 +02:00
parent 3af7c29b7f
commit dc1ad82080

View File

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