-
Notifications
You must be signed in to change notification settings - Fork 7
/
clock.py
52 lines (32 loc) · 1.59 KB
/
clock.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
from apscheduler.schedulers.blocking import BlockingScheduler
from requests_to_schedule import parsing_timetable
from rutetider import Timetable, CurrentDates
from additional_data import database_url
import datetime
sched = BlockingScheduler()
def weekdays_delete():
Timetable(database_url).clear_timetable()
def everyday_dates_refreshing():
today = datetime.datetime.today().strftime('%d.%m.%Y')
tomorrow = (datetime.datetime.today() + datetime.timedelta(1)).strftime('%d.%m.%Y')
CurrentDates(database_url).add_dates(today, tomorrow)
def weekdays():
native_day = datetime.datetime.now() + datetime.timedelta()
weekday = datetime.datetime.today().weekday()
first_day = native_day + datetime.timedelta(-weekday)
last_day = first_day + datetime.timedelta(6)
parsing_timetable(first_day.strftime("%d.%m.%Y"), last_day.strftime("%d.%m.%Y"))
def weekend_delete():
Timetable(database_url).clear_timetable()
def weekend():
native_day = datetime.datetime.now() + datetime.timedelta()
weekday = datetime.datetime.today().weekday()
first_day = native_day + datetime.timedelta(-weekday)
last_day = first_day + datetime.timedelta(6)
parsing_timetable(first_day.strftime("%d.%m.%Y"), last_day.strftime("%d.%m.%Y"))
sched.add_job(everyday_dates_refreshing, 'cron', day_of_week='mon-sun', hour=22)
sched.add_job(weekdays_delete, 'cron', day_of_week='mon-thu', hour=22)
sched.add_job(weekdays, 'cron', day_of_week='mon-thu', hour=22)
sched.add_job(weekend_delete, 'cron', day_of_week=5, hour=22)
sched.add_job(weekend, 'cron', day_of_week=5, hour=22)
sched.start()