だから私は、私は特定の事柄のタイムゾーンを維持しようとしたこの種のものを行なったし、それはので、ここで私をたくさん助けた最後の時間は、私が試してみてくださいしたいものです。ここではpytzライブラリを使用しているので、それをインストールする必要があります。次に、必要な時間帯に変更することもできます。
from datetime import datetime, time
from time import sleep
import pytz
def get_times():
my_timezone = pytz.timezone('America/Los_Angeles')
last_time = my_timezone.normalize(datetime.now(tz=my_timezone))
midnight = my_timezone.localize(datetime.combine(last_time.date(), time.max))
return last_time, midnight
def main():
last_time, midnight = get_times()
while True:
if last_time > midnight:
# It's passed midnight we need to run it
# do work here...
# now we need to update midnight to todays midnight
last_time, midnight = get_times()
else:
# we shouldn't run the work just update last time
last_time, _ = get_times()
sleep(10)
if __name__ == '__main__':
main()
なぜcronジョブを使用しないのですか? –
Pythonでは論理的で、 '&& 'ではなく' and'です。 –