Compare commits

..

No commits in common. "d048878e589f5595525a5006f6f483f767d08bc1" and "d61c1d0f1b4041bed446865fe89c4066cc12c0f1" have entirely different histories.

2 changed files with 17 additions and 53 deletions

31
main.py
View File

@ -44,17 +44,16 @@ class App:
def __init__(self):
logging.basicConfig()
self.logging = logging.getLogger("app")
self.logging.setLevel(logging.DEBUG)
with open("config.json", "r") as f:
self.CONFIG = json.load(f)
self.logging.setLevel(self.CONFIG["logging"])
self.logging.info("configuration loaded")
self.M = self.authenticate()
self.logging.info("authentication succeeded")
self.mods = {}
self.install("elicense", mods.elicense)
self.alive = True
signal.signal(signal.SIGTERM, lambda a,b: self.exit())
@ -91,18 +90,13 @@ class App:
return M
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)
logger = logging.getLogger("mod."+name)
self.mods[name] = mod.init(self.CONFIG["mods"][name], logger)
def run(self):
self.install("elicense", mods.elicense)
while self.alive:
try:
self.cycle()
@ -110,12 +104,13 @@ class App:
except Exception as e:
self.logging.warning("cycle aborted:", e)
for mod in self.mods:
self.mods[mod].cycle()
for i in range(self.CONFIG["interval"]):
if not self.alive: break
time.sleep(1)
del self.mods
def cycle(self):
items = self.M.notifications(
account_id = self.CONFIG["master"],
@ -128,8 +123,7 @@ class App:
self.reply(st, "handling aborted: {}".format(e))
self.M.notifications_dismiss(id = item["id"])
for mod in self.mods:
self.mods[mod].cycle()
# TODO: call mod cycles
def exit(self):
self.alive = False
@ -137,11 +131,10 @@ class App:
def reply(self, st, msg):
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.M.status_post(
# status = "@{} {}".format(st["account"]["acct"], msg),
# in_reply_to_id = st["id"])
except Exception as e:
self.logging.error("reply failure:", msg, "(", e, ")")

View File

@ -22,18 +22,6 @@ class Mod:
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):
if len(self.targets) == 0:
return
@ -42,7 +30,7 @@ class Mod:
url = self.URL+"p04a.action",
data = {
"b.processCd": "A",
"b.kamokuCd" : self.calender.params["kamokuCd"],
"b.kamokuCd" : 0,
"b.page" : 1,
"b.schoolCd" : self.CONFIG["school"],
})
@ -74,12 +62,12 @@ class Mod:
data = {
"b.schoolCd" : self.CONFIG["school"],
"b.processCd" : "V",
"b.kamokuCd" : self.calender.params["kamokuCd"],
"b.instructorTypeCd" : self.calender.params["instructorTypeCd"],
"b.kamokuCd" : 0,
"b.instructorTypeCd" : 0,
"b.dateInformationType": date,
"b.infoPeriodNumber" : slot,
"b.carModelCd" : self.calender.params["carModelCd"],
"b.instructorCd" : self.calender.params["instructorCd"],
"b.carModelCd" : self.calender.carModel,
"b.instructorCd" : 0,
"b.page" : 1,
"b.groupCd" : self.calender.group,
})
@ -120,12 +108,6 @@ class Calender:
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):
for avail in self.avails:
if avail[0] == date and avail[1] == str(slot):
@ -149,14 +131,3 @@ TIMETABLE = {
RE_ALERT = re.compile(r"window\.alert\('(.*)'\)")
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_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))