Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime, timedelta
- import sys
- import os
- from flask import Flask
- from apscheduler.schedulers.background import BackgroundScheduler
- app = Flask(__name__)
- scheduler = BackgroundScheduler()
- def alarm():
- print('Alarm! This alarm was scheduled')
- def hello_el():
- print("Hey, El! Get shit done!")
- @app.route('/')
- def hello_world():
- scheduler.add_job(hello_el, 'interval', seconds=2)
- return 'Hello World!'
- if __name__ == '__main__':
- url = 'sqlite:///hello.sqlite3'
- scheduler.add_jobstore('sqlalchemy', url=url)
- alarm_time = datetime.now() + timedelta(seconds=10)
- scheduler.add_job(alarm, 'interval', seconds=3)
- print('To clear the alarms, delete the example.sqlite file.')
- print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
- try:
- scheduler.start()
- app.run(host='localhost')
- except (KeyboardInterrupt, SystemExit):
- print("You want to stop the progrm.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement