-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheduler.py
More file actions
39 lines (34 loc) · 1.14 KB
/
scheduler.py
File metadata and controls
39 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import schedule
import time
from datetime import datetime
from models.Schedule import ScheduleModel
from app import app as app
from db import db
def job():
schedules = ScheduleModel.find_all()
current_time = datetime.now().strftime('%X')
print("I'm working... " + current_time)
current_weekday = datetime.now().weekday()
for schedule in schedules:
if schedule.time == current_time:
print("MATCHING TIMES")
for schedule_day in schedule.schedule_days:
print(schedule_day.day + " vs " + current_weekday)
if current_weekday == schedule_day.day:
print("MATCHING DAYS")
def scheduler():
db.init_app(app)
app.app_context().push()
while True:
# schedule.every(10).seconds.do(job)
# while True:
# schedule.run_pending()
#
print(datetime.now().time())
if datetime.now().time().second == 0:
print('in scheduler')
schedule.every(1).minutes.do(job)
while 1:
schedule.run_pending()
elif datetime.now().time().second < 54:
time.sleep(5)