예제 #1
0
def classes():
    class_list = select('select * from member')
    class_dict = dict()

    for i in class_list:
        class_dict[i['class']] = i['name']
    return class_dict
예제 #2
0
    def get_tutor(self):
        if self.stuid != -1:
            tutor = select_one('select *from tutor where StuID = ?',
                               self.stuid)

            if PY2:
                self.tutor = tutor['tutor'].encode('utf8')
                self.tutor_mail = tutor['mail'].encode('utf8')
            else:
                self.tutor = tutor['tutor']
                self.tutor_mail = tutor['mail']
            tutor_info = dict()
            tutor_info['status'] = 1
            tutor_info['same_tutor'] = []
            if self.tutor == '#N/A':
                tutor_info['status'] = 0
            else:
                temp = select(
                    'select *from tutor where tutor = ? and stuid <> ?',
                    self.tutor, self.stuid)

                if temp:
                    if PY2:
                        for i in temp:
                            i['name'] = i['name'].encode('utf8')
                            i['sex'] = i['sex'].encode('utf8')
                            i['campus'] = i['campus'].encode('utf8')
                    tutor_info['same_tutor'] = temp
                    # [{},{}]
            return tutor_info
        else:
            return "您尚未绑定学号!"
예제 #3
0
def classes():
    class_list = select('select * from member')
    class_dict = dict()

    for i in class_list:
        class_dict[i['class']] = i['name']
    return class_dict
예제 #4
0
    def get_tutor(self):
        if self.stuid != -1:
            tutor = select_one('select *from tutor where StuID = ?', self.stuid)

            if PY2:
                self.tutor = tutor['tutor'].encode('utf8')
                self.tutor_mail = tutor['mail'].encode('utf8')
            else:
                self.tutor = tutor['tutor']
                self.tutor_mail = tutor['mail']
            tutor_info = dict()
            tutor_info['status'] = 1
            tutor_info['same_tutor'] = []
            if self.tutor == '#N/A':
                tutor_info['status'] = 0
            else:
                temp = select('select *from tutor where tutor = ? and stuid <> ?', self.tutor, self.stuid)

                if temp:
                    if PY2:
                        for i in temp:
                            i['name'] = i['name'].encode('utf8')
                            i['sex'] = i['sex'].encode('utf8')
                            i['campus'] = i['campus'].encode('utf8')
                    tutor_info['same_tutor'] = temp
                    # [{},{}]
            return tutor_info
        else:
            return "您尚未绑定学号!"
예제 #5
0
def get_activity_info():
    activities = select('select nid,title,url from notecontent order by nid desc limit 30')
    for i in activities:
        i['time'] = __transfer_time(i['nid'])
        read_info = get_read_info(i['nid'], simple=True)
        if read_info:
            i['read'] = read_info['read_list']
            i['unread'] = read_info['unread_list']
    return activities
예제 #6
0
def get_activity_info():
    activities = select(
        'select nid,title,url from notecontent order by nid desc limit 30')
    for i in activities:
        i['time'] = __transfer_time(i['nid'])
        read_info = get_read_info(i['nid'], simple=True)
        if read_info:
            i['read'] = read_info['read_list']
            i['unread'] = read_info['unread_list']
    return activities
예제 #7
0
def stu(classes_seq):
    """
    :param classes_seq: list of class name
    :return: {class_name:[(stuid,stu_name),()...],class_name2:[(),()]}
    """
    if len(classes_seq) < 1:
        return -1
    stu_dict = dict()

    for i in classes_seq:
        stus = select('select stuid,name from stuinfo where class=?', i)
        result = [(j['stuid'], j['name']) for j in stus]
        stu_dict[i] = result
    return stu_dict
예제 #8
0
def stu(classes_seq):
    """
    :param classes_seq: list of class name
    :return: {class_name:[(stuid,stu_name),()...],class_name2:[(),()]}
    """
    if len(classes_seq) < 1:
        return -1
    stu_dict = dict()

    for i in classes_seq:
        stus = select('select stuid,name from stuinfo where class=?', i)
        result = [(j['stuid'],j['name']) for j in stus]
        stu_dict[i] = result
    return stu_dict
예제 #9
0
def history_articles(stuid):
    send_info = select("select nid,stuids from noteindex")

    if not send_info:
        return None

    nids = [i['nid'] for i in send_info if str(stuid) in i['stuids']]

    articles = []
    article_dict = dict()
    article_dict['articles'] = dict()
    for x in nids:
        re = select_one('select nid,title,url from notecontent where nid =?', x)
        if re is None:
            continue
        articles.append([re['nid'], re['title'], re['url']])
    return articles
예제 #10
0
def history_articles(stuid):
    send_info = select("select nid,stuids from noteindex")

    if not send_info:
        return None

    nids = [i['nid'] for i in send_info if str(stuid) in i['stuids']]

    articles = []
    article_dict = dict()
    article_dict['articles'] = dict()
    for x in nids:
        re = select_one('select nid,title,url from notecontent where nid =?',
                        x)
        if re is None:
            continue
        articles.append([re['nid'], re['title'], re['url']])
    return articles
예제 #11
0
def __handle_mes_key(msg, count=False, stu=False):  # 未读消息处理
    if stu:
        stuid = msg
    else:
        stuid = get_stuid(msg['FromUserName'])

    send_info = select('select nid,stuids from noteindex')
    if not send_info:
        return ''

    # 发送给某学生的所有消息
    send = [j['nid'] for j in send_info if str(stuid) in j['stuids']]
    if not send:
        return ''

    read_info = select('select nid,readlist from noteresponse')
    if not read_info:
        return ''

    # 该学生已读的所有消息
    read = [i['nid'] for i in read_info if str(stuid) in i['readlist']]

    not_read = list(set(send) - set(read))
    if not not_read:
        return ''

    send_content = select(
        'select nid,title,picurl,url from notecontent order by nid desc limit 100'
    )

    if count:
        temp = []
        for x in send_content:
            if x['nid'] in not_read:
                temp.append({'title': x['title'], 'url': x['url']})
        return {
            'read': len(read),
            'not_read': len(not_read),
            'not_read_content': temp
        }

    def transfer_url(nid):
        url = ADDRESS + '/code/' + str(nid)
        post_url = WxApiUrl.oauth2_new_page.format(appid=APP_ID,
                                                   redirect_url=url)
        return post_url

    send_content = [(x['title'], '', x['picurl'], transfer_url(x['nid']))
                    for x in send_content if x['nid'] in not_read][:8]

    if len(send_content) == 0:
        head_str = news_rep_front % (msg['FromUserName'], msg['ToUserName'],
                                     str(int(time.time())), 1)
        middle_str = news_rep_middle % (
            '当前没有未读消息哦~', '',
            'http://www.nju.edu.cn/_upload/tpl/01/36/310/template310/images/logo.png',
            'http://weixin.njunova.com')
        return __res_news_msg(head_str + middle_str + news_rep_back)

    middle_str = ''

    # 只返回前8条未读消息
    for i in send_content:
        middle_str += news_rep_middle % i

    head_str = news_rep_front % (msg['FromUserName'], msg['ToUserName'],
                                 str(int(time.time())), len(send_content))
    content = head_str + middle_str + news_rep_back
    return __res_news_msg(content)
예제 #12
0
def get_all_users():
    return select('select openid,stuid from biding ')
예제 #13
0
def __handle_mes_key(msg, count=False, stu=False): # 未读消息处理
    if stu:
        stuid = msg
    else:
        stuid = get_stuid(msg['FromUserName'])

    send_info = select('select nid,stuids from noteindex')
    if not send_info:
        return ''

    # 发送给某学生的所有消息
    send = [j['nid'] for j in send_info if str(stuid) in j['stuids']]
    if not send:
        return ''

    read_info = select('select nid,readlist from noteresponse')
    if not read_info:
        return ''

    # 该学生已读的所有消息
    read = [i['nid'] for i in read_info if str(stuid) in i['readlist']]

    not_read = list(set(send)-set(read))
    if not not_read:
        return ''

    send_content = select('select nid,title,picurl,url from notecontent order by nid desc limit 100')

    if count:
        temp = []
        for x in send_content:
            if x['nid'] in not_read:
                temp.append({'title': x['title'], 'url': x['url']})
        return {'read': len(read),
                'not_read': len(not_read),
                'not_read_content': temp}


    def transfer_url(nid):
        url = ADDRESS + '/code/' + str(nid)
        post_url = WxApiUrl.oauth2_new_page.format(appid=APP_ID, redirect_url=url)
        return post_url

    send_content = [(x['title'], '', x['picurl'], transfer_url(x['nid'])) for x in send_content if x['nid'] in not_read][:8]

    if len(send_content) == 0:
        head_str = news_rep_front % (msg['FromUserName'], msg['ToUserName'], str(int(time.time())), 1)
        middle_str = news_rep_middle % ('当前没有未读消息哦~', '',
                                        'http://www.nju.edu.cn/_upload/tpl/01/36/310/template310/images/logo.png',
                                        'http://weixin.njunova.com')
        return __res_news_msg(head_str+middle_str+news_rep_back)

    middle_str=''

    # 只返回前8条未读消息
    for i in send_content:
        middle_str += news_rep_middle % i

    head_str = news_rep_front % (msg['FromUserName'], msg['ToUserName'], str(int(time.time())),len(send_content))
    content = head_str+middle_str+news_rep_back
    return __res_news_msg(content)
예제 #14
0
def get_all_users():
    return select('select openid,stuid from biding ')