def _getclass(self, userid, password):

        # 使用nowdates的app上下文防止
        with nowdates.app.app_context():
            try:
                nowtime = nowdates.get()
                user = get_curriculum_from_jiaowu(userid, password,
                                                  nowtime['xn'])
                kb = user.get_all()
                for i in kb:
                    for j in i:
                        if j is None: continue
                        curriculum = Curriculum.query.filter_by(
                            userid=userid,
                            school_year=nowtime['xn'],
                            week=j["week"],
                            class_time=j['class_time'],
                            class_name=j['class_name'],
                            teacher=j['teacher'],
                            location=j['location'],
                            class_day=j['class_day']).first()
                        if curriculum is not None: continue
                        curriculum = Curriculum(userid=userid,
                                                school_year=nowtime['xn'],
                                                week=j["week"],
                                                class_time=j['class_time'],
                                                class_name=j['class_name'],
                                                teacher=j['teacher'],
                                                location=j['location'],
                                                class_day=j['class_day'])
                        db.session.add(curriculum)
                db.session.commit()
            except Exception as e:
                print("错误:", e)
Ejemplo n.º 2
0
def dealtextmsg(content, fromusername, tousername):
    if '成绩' in content:
        wxuser = WXUser.query.filter(WXUser.openid == fromusername).first()
        if wxuser is None or wxuser.userid is None:
            keyword = Keywords.query.filter(
                Keywords.keyword == 'can_not_find_account').first()
            return generate_return(keyword.reply, fromusername, tousername)
        else:
            try:
                exam = verifyjw.get_exam("token", wxuser.userid,
                                         nowdates.get()['xn'])
                if exam[0] == None:
                    return generate_return(
                        Keywords.query.filter(
                            Keywords.keyword ==
                            'can_not_find_exam').first().reply, fromusername,
                        tousername)
            # 教务网不可访问的错误s
            except requests.exceptions.ConnectionError:
                keyword = Keywords.query.filter(
                    Keywords.keyword == 'can_not_request_jiaowu').first()
                return generate_return(keyword.reply, fromusername, tousername)
            # exam = verifyjw.get_exam(token, wxuser.userid, "2019-2020-1")
            if len(exam) == 1 and exam[0] is None:
                msg = Keywords.query.filter(
                    Keywords.keyword == 'can_not_request_jiaowu').first().reply
            else:
                msg = ""
                for i in exam:
                    msg += "考试名称:" + i['kcmc'] + '\n' + "考试性质:" + i[
                        'ksxzmc'] + '\n' + "课程性质:" + str(
                            i.get('kclbmc')) + '\n' + "总成绩:" + str(
                                i.get('zcj')) + '\n\n'

        return generate_return(msg, fromusername, tousername)
    elif '情话' in content:
        res = requests.get("https://chp.shadiao.app/api.php?from=hynuxyk")
        return generate_return(res.text, fromusername, tousername)
    elif '朋友圈文案' in content:
        res = requests.get("https://pyq.shadiao.app/api.php?from=hynuxyk")
        return generate_return(res.text, fromusername, tousername)
    elif '毒鸡汤' in content:
        res = requests.get("https://du.shadiao.app/api.php?from=hynuxyk")
        return generate_return(res.text, fromusername, tousername)
    elif '骂我' in content:
        res = requests.get(
            "https://nmsl.shadiao.app/api.php?level=min?from=hynuxyk")
        return generate_return(res.text, fromusername, tousername)
    else:
        keywords = Keywords.query.all()
        for i in keywords:
            if i.keyword in content:
                return generate_return(i.reply, fromusername, tousername)
        return ""
Ejemplo n.º 3
0
def dealtextmsg(content, fromusername, tousername):
    msg = u"我收到啦,看到信息就回你"
    if '成绩' in content:
        wxuser = WXUser.query.filter(WXUser.openid == fromusername).first()
        if wxuser is None or wxuser.userid is None:
            msg = u"这里没有你的教务网账号哦,请前往[订阅通知]-[绑定教务网]绑定你的教务网账号哦(*^▽^*)"
            return {
                "ToUserName":
                fromusername,
                "FromUserName":
                tousername,
                "CreateTime":
                int(time.time()),
                "MsgType":
                "text",
                "Content":
                "<a href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3f45ab7ab0b12aed&redirect_uri=https%3A%2F%2Fwww.hynuxyk.club%2Fwx/&response_type=code&scope=snsapi_userinfo&state=bindjw#wechat_redirect'>点击绑定教务网</a>",
            }
        else:
            exam = verifyjw.get_exam("token", wxuser.userid,
                                     nowdates.get()['xn'])
            # exam = verifyjw.get_exam(token, wxuser.userid, "2019-2020-1")
            if len(exam) == 1 and exam[0] is None:
                msg = u"你这个学期都还没有成绩粗来(〃>皿<)"
            else:
                msg = ""
                for i in exam:
                    msg += "考试名称:" + i['kcmc'] + '\n' + "考试性质:" + i[
                        'ksxzmc'] + '\n' + "课程性质:" + i[
                            'kclbmc'] + '\n' + "总成绩:" + i['zcj'] + '\n\n'

    return {
        "ToUserName": fromusername,
        "FromUserName": tousername,
        "CreateTime": int(time.time()),
        "MsgType": "text",
        "Content": msg + "或者前往小程序-【课表成绩】-【成绩】查询当前学期的成绩,平时分和排名",
    }
Ejemplo n.º 4
0
 def _getclass(self, userid, password):
     # 使用nowdates的app上下文防止
     with nowdates.app.app_context():
         try:
             token = verifyjw.login(userid, password)
             nowtime = nowdates.get()
             for i in range(25):
                 kecheng = verifyjw.getclass(token, userid, nowtime['xn'],
                                             str(i))
                 for j in kecheng:
                     if j is None: continue
                     curriculum = Curriculum.query.filter_by(
                         userid=userid,
                         school_year=nowtime['xn'],
                         week=i,
                         class_time=j['kcsj'],
                         class_name=j['kcmc'],
                         teacher=j['jsxm'],
                         location=j['jsmc'],
                         begintime=j['kssj'],
                         endtime=j['jssj'],
                         cycle=j['kkzc']).first()
                     if curriculum is not None: continue
                     curriculum = Curriculum(userid=userid,
                                             school_year=nowtime['xn'],
                                             week=i,
                                             class_time=j['kcsj'],
                                             class_name=j['kcmc'],
                                             teacher=j['jsxm'],
                                             location=j['jsmc'],
                                             begintime=j['kssj'],
                                             endtime=j['jssj'],
                                             cycle=j['kkzc'])
                     db.session.add(curriculum)
             db.session.commit()
         except Exception as e:
             print("错误:", e)
Ejemplo n.º 5
0
def get_time():
    return nowdates.get()