-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (38 loc) · 1.56 KB
/
main.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
53
#!/usr/bin/python
# -*- coding:utf-8 -*-
import logging.handlers
import logging
import os
import sys
path = os.path.dirname(__file__)
logging.getLogger().setLevel(logging.NOTSET)
logging.captureWarnings(False)
# Silence scheduling messages
logging.getLogger("apscheduler.scheduler").setLevel(logging.ERROR)
console = logging.StreamHandler(sys.stdout)
console.setLevel(logging.INFO)
console.setFormatter(logging.Formatter("[{levelname:s}] {message:s}", style="{"))
logging.getLogger().addHandler(console)
if not os.path.exists(os.path.join(os.path.dirname(__file__), "res/logs/")):
os.makedirs(os.path.join(os.path.dirname(__file__), "res/logs/"))
file = logging.handlers.RotatingFileHandler(filename=os.path.join(path, "res/logs/app.log"),
maxBytes=1 << 20, backupCount=10)
file.setLevel(logging.DEBUG)
file.setFormatter(logging.Formatter("[{levelname:s}]({asctime:s} {name:s}) {message:s}", style="{"))
logging.getLogger().addHandler(file)
logger = logging.getLogger(__file__)
logger.info("Initialising program")
from apscheduler.schedulers.blocking import BlockingScheduler
from modules.organiser.organiser import Organiser
# Create an organiser and schedule it to update indefinitely
organiser = Organiser()
organiser.update()
scheduler = BlockingScheduler()
scheduler.add_job(organiser.update, trigger="cron", minute="*/15", hour="*", day="*", month="*", day_of_week="*")
try:
scheduler.start()
except (KeyboardInterrupt, SystemExit) as cause:
logger.exception(cause)
finally:
scheduler.shutdown()
logging.shutdown()