convert to sydney time

main
Shane 7 months ago
parent f0c84f8660
commit 827adb4730
  1. 26
      check_x_capacity.py

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import logging import logging
import pytz
logging.basicConfig( logging.basicConfig(
filename='/home/shane/foodie_automator/logs/check_x_capacity.log', filename='/home/shane/foodie_automator/logs/check_x_capacity.log',
@ -99,27 +100,26 @@ def display_author_status(author):
"""Display detailed status for a single author.""" """Display detailed status for a single author."""
username = author['username'] username = author['username']
can_post, remaining, reset = check_author_rate_limit(author) can_post, remaining, reset = check_author_rate_limit(author)
reset_time = datetime.fromtimestamp(reset, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S') reset_time_utc = datetime.fromtimestamp(reset, tz=timezone.utc)
reset_time_str = reset_time_utc.strftime('%Y-%m-%d %H:%M:%S UTC')
# Only check API if no scripts are running # Convert to Sydney time
if not is_any_script_running(): try:
api_remaining, api_reset = get_x_rate_limit_status(author) sydney_tz = pytz.timezone('Australia/Sydney')
if api_remaining is not None: reset_time_sydney = reset_time_utc.astimezone(sydney_tz)
api_reset_time = datetime.fromtimestamp(api_reset, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S') reset_time_sydney_str = reset_time_sydney.strftime('%Y-%m-%d %H:%M:%S %Z')
# Use API values as primary display except Exception as e:
remaining = api_remaining reset_time_sydney_str = 'N/A'
reset_time = api_reset_time
can_post = remaining > 0
status = "" if can_post else "" status = "" if can_post else ""
print(f"\n{status} {username}:") print(f"\n{status} {username}:")
print(f" • Remaining tweets: {remaining}/17") print(f" • Remaining tweets: {remaining}/17")
print(f" • Reset time: {reset_time}") print(f" • Reset time (UTC): {reset_time_str}")
print(f" • Reset time (Sydney): {reset_time_sydney_str}")
print(f" • Can post: {'Yes' if can_post else 'No'}") print(f" • Can post: {'Yes' if can_post else 'No'}")
# Send alert if capacity is full # Send alert if capacity is full
if remaining == 0: if remaining == 0:
send_capacity_alert(username, remaining, reset_time) send_capacity_alert(username, remaining, reset_time_str)
# Show API status for verification # Show API status for verification
if not is_any_script_running(): if not is_any_script_running():

Loading…
Cancel
Save