This repository has been archived by the owner on Feb 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (57 loc) · 2 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from quip4aha import sysconf, startd, cleanupd, week # quip4aha has set the CST timezone
from NewDoc import NewDoc
from AssignHost import AssignHost
from UpdateWeather import UpdateWeather
#from Bot import Chatbot # __main__ only
from traceback import format_exc
from logging import getLogger
import logging
logging.basicConfig(level=logging.INFO)
from datetime import datetime
from time import sleep
from flask import Flask, request
from schedule import Scheduler
app = Flask(__name__)
@app.route('/')
def home():
return "Everything's 200 OK."
@app.route('/a')
def assign():
AssignAction = AssignHost()
return AssignAction.do()
@app.route('/newdoc')
def newdoc():
NewDocAction = NewDoc()
return NewDocAction.do()
@app.route('/updateweather')
def updateweather():
UpdateAction = UpdateWeather()
return UpdateAction.do()
@app.errorhandler(Exception)
def handle_exception(e):
tb = format_exc()
app.logger.error(datetime.today().strftime('%m%d(%w)%H {}').format(tb.replace('\n','\n--- ')))
return "<pre>%s</pre>" % tb, getattr(e,'code',500)
class Scheduler4AHA(Scheduler):
def __init__(self):
Scheduler.__init__(self)
fc = app.test_client() # Flask client emulator
from Bot import Chatbot
cb = Chatbot()
# Schedule uses the local timezone, which has been set to CST.
self.every().friday.at("16:10").do(fc.get, '/newdoc')
self.every().sunday.at("07:27").do(fc.get, '/updateweather')
j = self.every().tuesday.at("09:00").do(startd, cb.run, cb.quit)
if week.DaysTo('last Tuesday') == 0:
j.run()
self.every().tuesday.at("22:00").do(cb.quit)
self.every().wednesday.at("07:27").do(fc.get, '/updateweather')
def run(self):
while 1:
self.run_pending()
while self.idle_seconds > 0:
sleep(self.idle_seconds)
if __name__ == '__main__':
startd(Scheduler4AHA().run)
app.run(host=sysconf['host'], port=sysconf['port'])
cleanupd()