Compare commits
No commits in common. "d048878e589f5595525a5006f6f483f767d08bc1" and "d61c1d0f1b4041bed446865fe89c4066cc12c0f1" have entirely different histories.
d048878e58
...
d61c1d0f1b
31
main.py
31
main.py
@ -44,17 +44,16 @@ class App:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
self.logging = logging.getLogger("app")
|
self.logging = logging.getLogger("app")
|
||||||
|
self.logging.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
with open("config.json", "r") as f:
|
with open("config.json", "r") as f:
|
||||||
self.CONFIG = json.load(f)
|
self.CONFIG = json.load(f)
|
||||||
self.logging.setLevel(self.CONFIG["logging"])
|
|
||||||
self.logging.info("configuration loaded")
|
self.logging.info("configuration loaded")
|
||||||
|
|
||||||
self.M = self.authenticate()
|
self.M = self.authenticate()
|
||||||
self.logging.info("authentication succeeded")
|
self.logging.info("authentication succeeded")
|
||||||
|
|
||||||
self.mods = {}
|
self.mods = {}
|
||||||
self.install("elicense", mods.elicense)
|
|
||||||
|
|
||||||
self.alive = True
|
self.alive = True
|
||||||
signal.signal(signal.SIGTERM, lambda a,b: self.exit())
|
signal.signal(signal.SIGTERM, lambda a,b: self.exit())
|
||||||
@ -91,18 +90,13 @@ class App:
|
|||||||
return M
|
return M
|
||||||
|
|
||||||
def install(self, name, mod):
|
def install(self, name, mod):
|
||||||
config = self.CONFIG["mods"].get(name)
|
|
||||||
if config is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
logger = logging.getLogger("mods."+name)
|
|
||||||
if "logging" in config:
|
|
||||||
logger.setLevel(config["logging"])
|
|
||||||
|
|
||||||
self.mods[name] = mod.init(config, logger)
|
|
||||||
self.logging.info("mod installed, "+name)
|
self.logging.info("mod installed, "+name)
|
||||||
|
|
||||||
|
logger = logging.getLogger("mod."+name)
|
||||||
|
self.mods[name] = mod.init(self.CONFIG["mods"][name], logger)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.install("elicense", mods.elicense)
|
||||||
while self.alive:
|
while self.alive:
|
||||||
try:
|
try:
|
||||||
self.cycle()
|
self.cycle()
|
||||||
@ -110,12 +104,13 @@ class App:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logging.warning("cycle aborted:", e)
|
self.logging.warning("cycle aborted:", e)
|
||||||
|
|
||||||
|
for mod in self.mods:
|
||||||
|
self.mods[mod].cycle()
|
||||||
|
|
||||||
for i in range(self.CONFIG["interval"]):
|
for i in range(self.CONFIG["interval"]):
|
||||||
if not self.alive: break
|
if not self.alive: break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
del self.mods
|
|
||||||
|
|
||||||
def cycle(self):
|
def cycle(self):
|
||||||
items = self.M.notifications(
|
items = self.M.notifications(
|
||||||
account_id = self.CONFIG["master"],
|
account_id = self.CONFIG["master"],
|
||||||
@ -128,8 +123,7 @@ class App:
|
|||||||
self.reply(st, "handling aborted: {}".format(e))
|
self.reply(st, "handling aborted: {}".format(e))
|
||||||
self.M.notifications_dismiss(id = item["id"])
|
self.M.notifications_dismiss(id = item["id"])
|
||||||
|
|
||||||
for mod in self.mods:
|
# TODO: call mod cycles
|
||||||
self.mods[mod].cycle()
|
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
self.alive = False
|
self.alive = False
|
||||||
@ -137,11 +131,10 @@ class App:
|
|||||||
|
|
||||||
def reply(self, st, msg):
|
def reply(self, st, msg):
|
||||||
try:
|
try:
|
||||||
self.M.status_post(
|
|
||||||
status = "@{} {}".format(st["account"]["acct"], msg),
|
|
||||||
in_reply_to_id = st["id"],
|
|
||||||
visibility = "direct")
|
|
||||||
self.logging.debug("reply:", msg)
|
self.logging.debug("reply:", msg)
|
||||||
|
#self.M.status_post(
|
||||||
|
# status = "@{} {}".format(st["account"]["acct"], msg),
|
||||||
|
# in_reply_to_id = st["id"])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logging.error("reply failure:", msg, "(", e, ")")
|
self.logging.error("reply failure:", msg, "(", e, ")")
|
||||||
|
|
||||||
|
@ -22,18 +22,6 @@ class Mod:
|
|||||||
|
|
||||||
self.ss = self.authenticate()
|
self.ss = self.authenticate()
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
res = self.ss.get(
|
|
||||||
url = self.URL+"logout.action",
|
|
||||||
params = {
|
|
||||||
"b.schoolCd": self.CONFIG["school"],
|
|
||||||
"senisakiCd": 4,
|
|
||||||
})
|
|
||||||
res.encoding = "shift_jis"
|
|
||||||
self.calender = Calender(res.text)
|
|
||||||
|
|
||||||
self.logging.info("logout succeeded")
|
|
||||||
|
|
||||||
def cycle(self):
|
def cycle(self):
|
||||||
if len(self.targets) == 0:
|
if len(self.targets) == 0:
|
||||||
return
|
return
|
||||||
@ -42,7 +30,7 @@ class Mod:
|
|||||||
url = self.URL+"p04a.action",
|
url = self.URL+"p04a.action",
|
||||||
data = {
|
data = {
|
||||||
"b.processCd": "A",
|
"b.processCd": "A",
|
||||||
"b.kamokuCd" : self.calender.params["kamokuCd"],
|
"b.kamokuCd" : 0,
|
||||||
"b.page" : 1,
|
"b.page" : 1,
|
||||||
"b.schoolCd" : self.CONFIG["school"],
|
"b.schoolCd" : self.CONFIG["school"],
|
||||||
})
|
})
|
||||||
@ -74,12 +62,12 @@ class Mod:
|
|||||||
data = {
|
data = {
|
||||||
"b.schoolCd" : self.CONFIG["school"],
|
"b.schoolCd" : self.CONFIG["school"],
|
||||||
"b.processCd" : "V",
|
"b.processCd" : "V",
|
||||||
"b.kamokuCd" : self.calender.params["kamokuCd"],
|
"b.kamokuCd" : 0,
|
||||||
"b.instructorTypeCd" : self.calender.params["instructorTypeCd"],
|
"b.instructorTypeCd" : 0,
|
||||||
"b.dateInformationType": date,
|
"b.dateInformationType": date,
|
||||||
"b.infoPeriodNumber" : slot,
|
"b.infoPeriodNumber" : slot,
|
||||||
"b.carModelCd" : self.calender.params["carModelCd"],
|
"b.carModelCd" : self.calender.carModel,
|
||||||
"b.instructorCd" : self.calender.params["instructorCd"],
|
"b.instructorCd" : 0,
|
||||||
"b.page" : 1,
|
"b.page" : 1,
|
||||||
"b.groupCd" : self.calender.group,
|
"b.groupCd" : self.calender.group,
|
||||||
})
|
})
|
||||||
@ -120,12 +108,6 @@ class Calender:
|
|||||||
|
|
||||||
self.avails = re.findall(RE_AVAIL_SLOT, text)
|
self.avails = re.findall(RE_AVAIL_SLOT, text)
|
||||||
|
|
||||||
self.params = {}
|
|
||||||
for name in RE_PARAMS:
|
|
||||||
m = re.search(RE_PARAMS[name], text)
|
|
||||||
if m is not None:
|
|
||||||
self.params[name] = m[1]
|
|
||||||
|
|
||||||
def checkAvailable(self, date, slot):
|
def checkAvailable(self, date, slot):
|
||||||
for avail in self.avails:
|
for avail in self.avails:
|
||||||
if avail[0] == date and avail[1] == str(slot):
|
if avail[0] == date and avail[1] == str(slot):
|
||||||
@ -149,14 +131,3 @@ TIMETABLE = {
|
|||||||
RE_ALERT = re.compile(r"window\.alert\('(.*)'\)")
|
RE_ALERT = re.compile(r"window\.alert\('(.*)'\)")
|
||||||
RE_ERROR = re.compile(r"<.*? class=\"errorTitle\">メッセージ<\/.*?>\s*<.*? class=\"errorDisp\">(.*?)<\/.*?>", re.MULTILINE)
|
RE_ERROR = re.compile(r"<.*? class=\"errorTitle\">メッセージ<\/.*?>\s*<.*? class=\"errorDisp\">(.*?)<\/.*?>", re.MULTILINE)
|
||||||
RE_AVAIL_SLOT = re.compile(r"^\s*<a href=\"#\" onclick=\"sendContent\('(\d+)','(\d+)','V',document\.getElementById\('formId'\)\)\">$")
|
RE_AVAIL_SLOT = re.compile(r"^\s*<a href=\"#\" onclick=\"sendContent\('(\d+)','(\d+)','V',document\.getElementById\('formId'\)\)\">$")
|
||||||
|
|
||||||
RE_PARAMS = {
|
|
||||||
"kamokuCd" : None,
|
|
||||||
"instructorTypeCd": None,
|
|
||||||
"carModelCd" : None,
|
|
||||||
"instructorCd" : None,
|
|
||||||
"groupCd" : None,
|
|
||||||
}
|
|
||||||
for name in RE_PARAMS:
|
|
||||||
RE_PARAMS[name] = re.compile(
|
|
||||||
r"<input type=\"hidden\" name=\"b.{0}\" value=\"(.*?)\" id=\"".format(name))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user