Пример #1
0
    def get_login(self, school, **kwargs):
        ''' 登录入口 与 异常处理 '''
        args = (school.login_url, school.exist_verify)
        try:
            res = self._get_api(*args, **kwargs)
        except OtherException as reqe:
            raise LoginException(self.code, to_text(str(reqe)))

        except RequestException:
            if school.proxies and not self.user.proxy_state:
                # 使用内网代理
                if self._switch_proxy():
                    # 存在内网代理会话
                    return True
                try:
                    res = self._get_api(*args, **kwargs)
                except RequestException:
                    raise LoginException(self.code, '教务系统异常,切用代理登录失败')
            else:

                if self.user.proxy_state:
                    raise LoginException(self.code, '教务系统异常,使用代理登录失败')
                else:
                    raise LoginException(self.code, '教务系统外网异常')

        self._handle_login_result(res, *args, **kwargs)
Пример #2
0
 def __init__(self,
              url,
              name=None,
              code=None,
              use_ex_handle=True,
              exist_verify=True,
              lan_url=None,
              proxies=None,
              priority_proxy=False,
              timeout=10,
              login_url_path=None,
              url_path_list=None,
              class_time_list=None,
              session=None):
     school = {
         'code': code,
         'lan_url': lan_url,
         'proxies': proxies,
         'timeout': timeout,
         'name': to_text(name),
         'exist_verify': exist_verify,
         'use_ex_handle': use_ex_handle,
         'priority_proxy': priority_proxy,
         'login_url': login_url_path or "/default2.aspx",
         'url_path_list': url_path_list or URL_PATH_LIST,
         'time_list': get_time_list(class_time_list or CLASS_TIME)
     }
     self.base_url = url.split('/default')[0] if url[-4:] == 'aspx' else url
     self.session = session or MemoryStorage()
     self.school = ObjectDict(school)
Пример #3
0
 def __init__(self,
              url,
              name=None,
              code=None,
              use_ex_handle=True,
              exist_verify=True,
              lan_url=None,
              proxies=None,
              priority_proxy=False,
              timeout=10,
              login_url_path='/default2.aspx',
              url_endpoint=URL_ENDPOINT,
              class_time_list=CLASS_TIME,
              session=MemoryStorage):
     school = {
         'code': code,
         'lan_url': lan_url,
         'proxies': proxies,
         'timeout': timeout,
         'name': to_text(name),
         'login_url': login_url_path,
         'url_endpoint': url_endpoint,
         'exist_verify': exist_verify,
         'use_ex_handle': use_ex_handle,
         'priority_proxy': priority_proxy,
         'time_list': get_time_list(class_time_list)
     }
     self.base_url = url.split('/default')[0] if url[-4:] == 'aspx' else url
     self.session = session(school['code'])
     self.school = ObjectDict(school)
Пример #4
0
    def _get_payload_by_bm(html, class_name):
        ''' 提取页面参数用于请求课表 '''
        pre_soup = BeautifulSoup(html, "html.parser")
        view_state = pre_soup.find(attrs={"name": "__VIEWSTATE"})['value']
        schedule_id_list = pre_soup.find(id='kb').find_all('option')
        class_name = to_text(class_name)
        schedule_id = ''
        for name in schedule_id_list:
            if name.text == class_name:
                schedule_id = name['value']
                break

        # 获取班级课表
        payload = {'__VIEWSTATE': view_state, 'kb': schedule_id}
        return payload
Пример #5
0
    def __init__(self, school, account, password, user_type):
        self._http = requests.Session()
        self._http.headers.update({
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) '
                          'AppleWebKit/537.36 (KHTML, like Gecko) '
                          'Chrome/62.0.3202.89 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded',
        })
        self.account = to_text(account)
        self.password = password
        self.user_type = user_type
        self.school = school.school
        self.base_url = self.school.url
        self.session = school.session

        if self.school.priority_porxy:
            self.set_proxy()
Пример #6
0
    def get_login(self, school, **kwargs):
        ''' 登录入口 与 异常处理 '''
        args = (school.login_url, school.exist_verify)
        try:
            res = self._get_api(*args, **kwargs)
        except OtherException as reqe:
            raise LoginException(self.school_code, to_text(str(reqe)))

        except RequestException:
            if school.proxies and not self.user.proxy_state:
                # 使用内网代理
                proxy_session = self._switch_proxy()
                if proxy_session:
                    # 存在内网代理会话
                    return True
                try:
                    res = self._get_api(*args, **kwargs)
                except RequestException:
                    raise LoginException(self.school_code, '教务系统异常,切用代理登录失败')
            else:

                if self.user.proxy_state:
                    raise LoginException(self.school_code, '教务系统异常,使用代理登录失败')
                else:
                    raise LoginException(self.school_code, '教务系统外网异常')

        # 处理登录结果
        try:
            self._handle_login_result(res)
        except CheckCodeException:
            try:
                # 验证码错误时,再次登录
                res = self._get_api(*args, **kwargs)
            except RequestException:
                raise LoginException(self.school_code, '教务系统请求异常')
            else:
                self._handle_login_result(res)

        return True
Пример #7
0
 def __init__(self, school_obj, account, password, user_type):
     self._http = requests.Session()
     self.school = school_obj.school
     self.base_url = school_obj.base_url
     self.session = school_obj.session
     self.user = ObjectDict({
         'account': to_text(account),
         'password': password,
         'user_type': user_type,
         'proxy_state': False
     })
     self._http.headers.update({
         'User-Agent':
         'Mozilla/5.0 (Windows NT 10.0; WOW64) '
         'AppleWebKit/537.36 (KHTML, like Gecko) '
         'Chrome/62.0.3202.89 Safari/537.36',
         'Content-Type':
         'application/x-www-form-urlencoded',
         'Referer':
         self.base_url + self.school.login_url
     })
     if self.school.priority_proxy:
         self.switch_proxy(True)
Пример #8
0
    def __init__(self, url, **kwargs):
        url = url.split('/default')[0] if url[-4:] == 'aspx' else url
        class_time_list = kwargs.get('class_time_list') or CLASS_TIME
        time_list = get_time_list(class_time_list)

        self.school = {
            'url': url,
            'debug': kwargs.get('debug'),
            'name': to_text(kwargs.get('name')),
            'code': kwargs.get('code'),
            'use_ex_handle': kwargs.get('use_ex_handle', True),
            'exist_verify': kwargs.get('exist_verify', True),
            'lan_url': kwargs.get('lan_url'),
            'proxies': kwargs.get('proxies'),
            'priority_proxy': kwargs.get('priority_proxy'),
            'timeout': kwargs.get('timeout', 10),
            'login_url': kwargs.get('login_url_path', '/default2.aspx'),
            'url_endpoint': kwargs.get('url_endpoint') or URL_ENDPOINT,
            'time_list': time_list
        }
        storage = kwargs.get('session', MemoryStorage)
        self.session = storage(self.school['code'])
        self.school = ObjectDict(self.school)
Пример #9
0
 def __call__(self, prefix=''):
     self.prefix = to_text(prefix)
     return self
Пример #10
0
 def get(self, key, default=None):
     key = self.key_name(key)
     value = self.redis.get(key)
     if value is None:
         return default
     return json.loads(to_text(value))
Пример #11
0
 def __str__(self):
     _repr = '{msg}'.format(msg=self.errmsg)
     msg = to_binary(_repr) if six.PY2 else to_text(_repr)
     return msg
Пример #12
0
 def __repr__(self):
     _repr = 'school_code:{school_code}, Error message: {name},{msg}'.format(
         school_code=self.school_code, name=self.name, msg=self.errmsg)
     msg = to_binary(_repr) if six.PY2 else to_text(_repr)
     return msg
Пример #13
0
 def __init__(self, prefix=''):
     self._data = {}
     self.prefix = to_text(prefix)