I'm beginning to learn python and I've tried to create a script to run a certain command at a certain time. This is what I have so far:
import datetime
day_of_week = datetime.date.today().weekday() # 0 is Monday, 6 is Sunday
time = datetime.datetime.now().time()
if day_of_week == 4 and (time >= datetime.time(2,45) and time < datetime.time(9)):
#do something
elif (day_of_week == 3 and time > datetime.time(22)) or (day_of_week == 4 and time < datetime.time(2,45)):
#wait until 2h45
else:
#do nothing
I want the script to continue only on a certain day and when it's around 19h00 PST/PDT (2h45 GMT/UTC). The one I wrote works fine with GMT/UTC, but I'm certain that it will fail when daylight savings starts or if I change the local timezone to a different one.
What could I do to make the script check for the current time in PST/PDT and continue from there, ignoring or converting the local timezone?