Ejemplo n.º 1
0
    def login(self, account, password):
        """
        登录校园卡网站
        :param str account: 校园卡卡号
        :param str password: 校园卡查询密码
        :return: {'code': 1, "msg": "登录失败,请重试"} 或 {'code': 0, 'msg': '登录成功'}
        """
        captcha_code = CardCaptcha(self.get_image(URL.card_captcha())).crack()
        data = {
            "sno": account,
            "pwd": base64.b64encode(str(password).encode("utf8")),
            "ValiCode": captcha_code,
            "remember": 1,
            "uclass": 1,
            "zqcode": "",
            "json": True,
        }

        result = self._login_execute(url=URL.card_login(), data=data)
        if result['code'] == 2:
            # 如果验证码错误,尝试递归重复登录
            return self.login(account, password)
        result['success'] = not result['code']
        if result['success']:
            self.verify = True
        else:
            raise AuthenticationException(result['msg'])
        return result
Ejemplo n.º 2
0
 def login(self, account, password):
     """
     登录教务系统 jwxt.njupt.edu.cn
     :param account: 南邮学号
     :param password: 密码
     :return: {'code': 1, "msg": "登录失败"} 或 {'code': 0, 'msg': '登录成功'}
     """
     captcha_code = ZhengfangCaptcha(self.get_image(
         URL.zhengfang_captcha())).crack()
     data = {
         "__VIEWSTATE": self._get_viewstate(URL.zhengfang_login()),
         'txtUserName': account,
         'TextBox2': password,
         'RadioButtonList1': "%D1%A7%C9%FA",
         "txtSecretCode": captcha_code,
         "Button1": "",
         "hidPdrs": "",
         "hidsc": ""
     }
     result = self._login_execute(url=URL.zhengfang_login(), data=data)
     if result['code'] == 2:
         # 如果验证码错误,尝试递归重复登录
         return self.login(account, password)
     result['success'] = not result['code']
     if result['success']:
         self.verify = True
     else:
         raise AuthenticationException(result['msg'])
     return result
Ejemplo n.º 3
0
 def login(self, username, password, login_type):
     captcha_code = str(LibraryCaptcha(self.get_image(self.URLs.CAPTCHA)))
     data = {
         'number': username,
         'passwd': password,
         'captcha': captcha_code,
         'select': login_type.value,
         'returnUrl': ''
     }
     res = self.post(url=self.URLs.LOGIN, data=data)
     res.encoding = 'utf-8'
     if '注销' in res.text:
         self.verify = True
     else:
         raise AuthenticationException('incorrect username or password')
Ejemplo n.º 4
0
 def login_by_username(self):
     captcha_code = ZhengfangCaptcha(self.s.get_image(
         self.URLs.CAPTCHA)).crack()
     data = {
         "__VIEWSTATE": self.s._get_viewstate(self.URLs.USERNAME_LOGIN),
         'txtUserName': self.username,
         'TextBox2': self.password,
         'RadioButtonList1': "%D1%A7%C9%FA",
         "txtSecretCode": captcha_code,
         "Button1": "",
         "hidPdrs": "",
         "hidsc": ""
     }
     r = self.s.post(url=self.URLs.USERNAME_LOGIN, data=data)
     if r.ok:
         if "请到信息维护中完善个人联系方式" in r.text:
             self.verified = True
             return {'success': True, 'msg': '登录成功'}
         elif "密码错误" in r.text:
             raise AuthenticationException('密码错误')
         elif "验证码不正确" in r.text:
             return self.login_by_username()
         else:
             raise AuthenticationException('未知错误')
Ejemplo n.º 5
0
    def check(self):
        """
        查询跑操次数

        :rtype: dict

        >>> rm.check()
        {'origin_number': 10, 'extra_number': 1, 'date_list': []}

        """
        url = 'http://zccx.tyb.njupt.edu.cn/student'
        data = {'number': self.student_id, 'name': self.name}
        response = self.post(url=url, data=data, allow_redirects=False)
        status = response.status_code
        if status == 302:
            raise AuthenticationException("学号、姓名不对应")

        soup = BeautifulSoup(response.content, 'lxml')

        number_text = soup.select('.list-group')[0].get_text()

        origin_number = int(self.digit_pattern.findall(number_text)[0])
        try:
            extra_number = int(self.digit_pattern.findall(number_text)[1])
        except IndexError:
            extra_number = 0

        try:
            raw_data_list = soup.find('tbody').find_all('tr')
            date_list = []
            for item in raw_data_list:
                date_str = re.sub(self.space_pattern, '', item.get_text())
                date = datetime.strptime(date_str, '%Y年%m月%d日%H时%M分')
                date = self.timezone.localize(date)
                date_list.append(date)

        except AttributeError:
            date_list = []

        return {
            'origin_number': origin_number,
            'extra_number': extra_number,
            'date_list': date_list
        }
Ejemplo n.º 6
0
    def _login(self, account, password):
        captcha_code = CardCaptcha(self.get_image(self.URLs.CAPTCHA)).crack()
        data = {
            "sno": account,
            "pwd": base64.b64encode(str(password).encode("utf8")),
            "ValiCode": captcha_code,
            "remember": 1,
            "uclass": 1,
            "zqcode": "",
            "json": True,
        }

        result = self._login_execute(url=self.URLs.LOGIN, data=data)
        if result['code'] == 2:
            # 如果验证码错误,尝试递归重复登录
            return self._login(account, password)
        result['success'] = not result['code']
        if result['success']:
            self.verify = True
        else:
            raise AuthenticationException(result['msg'])
        return result
Ejemplo n.º 7
0
 def login(self, account, password):
     # FIXME: 登录不可靠
     captcha_code = ZhengfangCaptcha(self.get_image(self.URLs.CAPTCHA)).crack()
     data = {
         "__VIEWSTATE": self._get_viewstate(self.URLs.LOGIN),
         'txtUserName': account,
         'TextBox2': password,
         'RadioButtonList1': "%D1%A7%C9%FA",
         "txtSecretCode": captcha_code,
         "Button1": "",
         "hidPdrs": "",
         "hidsc": ""
     }
     result = self._login_execute(url=self.URLs.LOGIN, data=data)
     if result['code'] == 2:
         # 如果验证码错误,尝试递归重复登录
         return self.login(account, password)
     result['success'] = not result['code']
     if result['success']:
         self.verify = True
     else:
         raise AuthenticationException(result['msg'])
     return result