Run automatic jobs in python

When I was looking for some good ideas for running cron jobs in Python, I found a library called ** APScheduler **.

Basically, you can do the following.

This time, I was planning to hit the API every 10 minutes and create a person who would save the data if the information could be obtained, so this requirement was fully satisfied. After that, it is quite convenient because there are methods to start Scheduler for each environment and framework.

Install AP Schuler

$ pip install apscheduler

Write the process

app/schedule.py


def hello_world():
  print("Hello World!")

sched = BackgroundScheduler(standalone=True,coalesce=True)
sched.add_job(hello_world, 'interval', minutes=1)
sched.start()

This will display "Hello World!" Every minute.

Read

I made an application with Flask, so if I read it with __init__.py, it worked fine in both the local environment and the production environment (Heroku).

app/__init__.py


import app.schedule

If I read the library and proceed, nothing will happen, but unexpectedly Japanese articles did not come out immediately, so I left it as a memorandum.

Recommended Posts

Run automatic jobs in python
Make cron-like jobs run regularly in Python
Run shell commands in python
Run Python unittests in parallel
Let's run "python -m antigravity" in python
Run shell command / python in R
Run unittests in Python (for beginners)
Run a simple algorithm in Python
Quadtree in Python --2
Python in optimization
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
Run AzureKinect in Python on Christmas Eve.
DCI in Python
quicksort in python
nCr in python
Run the Python interpreter in a script
N-Gram in Python
Programming in python
Automate jobs by manipulating files in Python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Run Python in C ++ on Visual Studio 2017
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Type Python scripts to run in QGIS Processing
Run Google Analytics API (core v3) in python
Run Python YOLOv3 in C ++ on Visual Studio 2017
Until you run the changefinder sample in python
[Mac] Run the RealSense D415 sample in Python
How to run Leap Motion in non-Apple Python
TensorFlow: Run data learned in Python on Android