How to execute a schedule by specifying the Python time zone and execution frequency

There are many explanations that it is executed at a specified time or at a specified interval, I couldn't find a case to specify the time zone and execution frequency at the same time, so I implemented it by the following method. I would appreciate it if you could teach me if there is a better way.

import datetime
import time
import schedule

#Start job def startJob():

Job registration performed every 10 minutes

    schedule.every(10).minutes.do(runJob)
    print('startJob:' + str(datetime.datetime.now()))

Main process you actually want to execute

def runJob():
    print('runJob:' + str(datetime.datetime.now()))

End job

def endJob():
    print('endJob:' + str(datetime.datetime.now()))
    for jobV in schedule.jobs:
        if 'runJob()' in str(jobV):

Delete the main processing job

            schedule.cancel_job(jobV)
            break

Define jobs to start and jobs to end

schedule.every().day.at("12:00").do(startJob)
schedule.every().day.at("13:00").do(endJob)

while True:
    schedule.run_pending()
    time.sleep(1)

Recommended Posts

How to execute a schedule by specifying the Python time zone and execution frequency
How to start the PC at a fixed time every morning and execute the python program
How to sort by specifying a column in the Python Numpy array.
I want to record the execution time and keep a log.
[Python3] Define a decorator to measure the execution time of a function
[Python] How to use the for statement. A method of extracting by specifying a range or conditions.
[Python Kivy] How to get the file path by dragging and dropping
How to get the date and time difference in seconds with python
How to stop a program in python until a specific date and time
How to erase the characters output by Python
How to measure execution time with Python Part 1
How to measure execution time with Python Part 2
How to pass the execution result of a shell command in a list in Python
[python] How to sort by the Nth Mth element of a multidimensional array
How to save a table scraped by python to csv
How to execute a command using subprocess in Python
How to unit test a function containing the current time using freezegun in python
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
[Mac] A super-easy way to execute system commands in Python and output the results
[Python] How to make a list of character strings character by character
How to switch the configuration file to be read by Python
How to use the __call__ method in a Python class
Build a Python environment and transfer data to the server
How to get the last (last) value in a list in Python
How to write a metaclass that supports both python2 and python3
How to execute external shell scripts and commands in python
How to override a user-defined method generated by python swig
[C / C ++] Pass the value calculated in C / C ++ to a python function to execute the process, and use that value in C / C ++.
How to start a simple WEB server that can execute cgi of php and python
How to quickly count the frequency of appearance of characters from a character string in Python?
How to calculate space background X-ray radiation (CXB) with python by specifying the flux range
An easy way to view the time taken in Python and a smarter way to improve it
How to pass the execution result of a shell command in a list in Python (non-blocking version)
Determine the date and time format in Python and convert to Unixtime
How to write a Python class
[sh] How to store the command execution result in a variable
How to determine the existence of a selenium element in Python
How to pass and study the Python 3 Engineer Certification Basic Exam
How to get the pixel value of the point from the satellite image by specifying the latitude and longitude
[Introduction to Python] How to split a character string with the split function
Process Splunk execution results using Python and save to a file
How to get followers and followers from python using the Mastodon API
How to check the memory size of a variable in Python
[Python] How to add rows and columns to a table (pandas DataFrame)
[Python] How to get the first and last days of the month
How to make a surveillance camera (Security Camera) with Opencv and Python
How to get the Python version
[Introduction to Python] How to use the in operator in a for statement?
How to check the memory size of a dictionary in Python
[Python] How to import the library
Python (from first time to execution)
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
Try to implement and understand the segment tree step by step (python)
How to send a request to the DMM (FANZA) API with python
[Introduction to Python] How to use the Boolean operator (and ・ or ・ not)
How to build Python and Jupyter execution environment with VS Code
How to display bytes in the same way in Java and Python
How to execute Linux commands on Windows by people who do not know Linux (ubuntu) [Until checking the operation of R and python]
[Python] How to save the installed package and install it in a new environment at once Mac environment
How to input a character string in Python and output it as it is or in the opposite direction.
[Python] How to specify the window display position and size of matplotlib