I am working on a crypto bot and using the datetime module to send price updates via SMS.
from datetime import datetime
current_time = datetime.now()
The datetime module is in military time (24 hour clock) and 7 hours ahead of my local time (PST), and I convert it by subtracting 7 from the time:
pst = abs(int(current_time.hour) - 7)
If the time is between 1 AM - 11 AM PST this works perfectly.
If the time is between 12 PM - 4 PM, I do:
if pst > 12 or pst == 0:
pst_time = abs(pst) - 12
5 PM - 12 AM PST doesn't work as current_time
= resets 0 to 7 and are < 12 which won't trigger the if statement.
Any advice on how to cleanly fix this without creating a huge table of numbers and setting them to a specific hour?