maidbot/mods/elicense.py

82 lines
1.8 KiB
Python
Raw Normal View History

import logging
import json
import requests
from html.parser import HTMLParser
def init(CONFIG, logger):
logger.setLevel(logging.DEBUG)
return Mod(CONFIG, logger)
class Mod:
def __init__(self, CONFIG, logging):
self.URL = "https://www.e-license.jp/el25/pc/"
self.CONFIG = CONFIG
self.logging = logging
self.targets = []
self.ss = self.authenticate()
def cycle(self):
res = self.ss.post(
url = self.URL+"p04a.action",
data = {
"b.processCd": "A",
"b.kamokuCd" : 0,
"b.page" : 1,
"b.schoolCd" : self.CONFIG["school"],
})
res.encoding = "shift_jis"
parser = ReservationListParser()
parser.feed(res.text)
return
def watch(self, date, slots):
self.logging.debug("watch request accepted: {} {}".format(+date+slots))
self.targets.append((date, slots))
def authenticate(self):
ss = requests.Session()
try:
res = ss.post(
url = self.URL+"p01a.action",
data = {
"b.studentId" : self.CONFIG["username"],
"b.password" : self.CONFIG["password"],
"b.schoolCd" : self.CONFIG["school"],
"b.processCd" : "",
"b.kamokuCd" : "",
"method:doLogin" : "ログイン".encode("shift_jis"),
})
self.logging.info("authenticated")
return ss
except Exception as e:
self.logging.error("authentication failure ({})".format(e))
return None
class ReservationListParser(HTMLParser):
path = []
def handle_starttag(self, tag, attrs):
self.path.append(tag)
c = [x[1] for x in attrs if x[0] == "class"]
if len(c) == 0:
return
if tag == "td":
print(c)
return
def handle_data(self, data):
return
def handle_endtag(self, tag):
self.path.pop()