Пример #1
0
def openid_handler(openid, nid):
    """
    update the mysql database using openid and post_url
    :param openid: openid of the user who read the specific article
    :param nid: the number of the article
    :return: return the result of the mysql's update
    """
    stuid = get_stuid(openid)
    read = int(time.time())

    read_info = select_one('select * from noteresponse where nID =?', nid)
    earliest = read_info['earlistread']
    read_id = read_info['readlist'].split(",")[:-1]  # "a list"
    read_time = read_info['readtime']
    read_pop = read_info['readpop']
    if earliest == 0:
        earliest = read
    latest = read
    if str(stuid) not in read_id:
        read_id.append(str(stuid))
        read_id = ','.join(read_id) + ','   #a string
        read_pop = read_pop + 1

    read_time = read_time + str(stuid) + ':' + str(read) + ','
    result = update('update noteresponse set readList=?,readtime=?,earlistread=?,latestread=?,readpop=? where nid=?',
                    read_id, read_time, earliest, latest, read_pop, nid)

    if result == 1:
        return 1
    else:
        log.warn("unable to upate noteresponse")
        return -1
Пример #2
0
def openid_handler(openid, nid):
    """
    update the mysql database using openid and post_url
    :param openid: openid of the user who read the specific article
    :param nid: the number of the article
    :return: return the result of the mysql's update
    """
    stuid = get_stuid(openid)
    read = int(time.time())

    read_info = select_one('select * from noteresponse where nID =?', nid)
    earliest = read_info['earlistread']
    read_id = read_info['readlist'].split(",")[:-1]  # "a list"
    read_time = read_info['readtime']
    read_pop = read_info['readpop']
    if earliest == 0:
        earliest = read
    latest = read
    if str(stuid) not in read_id:
        read_id.append(str(stuid))
        read_id = ','.join(read_id) + ','  #a string
        read_pop = read_pop + 1

    read_time = read_time + str(stuid) + ':' + str(read) + ','
    result = update(
        'update noteresponse set readList=?,readtime=?,earlistread=?,latestread=?,readpop=? where nid=?',
        read_id, read_time, earliest, latest, read_pop, nid)

    if result == 1:
        return 1
    else:
        log.warn("unable to upate noteresponse")
        return -1
Пример #3
0
def handle_history():
    if session.get('history_checked'):  # 确认是否从history路由跳转过来
        page = int(request.args.get('page'))
        if not page:
            return redirect('')
        result = history_articles(get_stuid(session['openid']))
        article_list = []
        for i in result:
            if len(i):
                if PY2:
                    article_list.append({
                        'title': i[1].encode('utf8'),
                        'url': i[2].encode('utf8')
                    })
                else:
                    article_list.append({'title': i[1], 'url': i[2]})
        article_list.reverse()
        if len(article_list) - page * 8 > 8:
            result = {
                'result': article_list[(page - 1) * 8:8 * page],
                'name': session['name']
            }
        else:
            result = {
                'result': article_list[(page - 1) * 8:],
                'name': session['name']
            }
    return jsonify(result)
Пример #4
0
def __save_into_database(content, openid):
    stuid = get_stuid(openid)
    result = insert('queryrecord', keyword=content, time=int(time.time()), username=stuid, describe='')

    if result == 1:
        return 0
    else:
        return -1
Пример #5
0
def __save_into_database(content, openid):
    stuid = get_stuid(openid)
    result = insert('queryrecord',
                    keyword=content,
                    time=int(time.time()),
                    username=stuid,
                    describe='')

    if result == 1:
        return 0
    else:
        return -1
Пример #6
0
def jiaowu(openid):
    stuid = get_stuid(openid)
    if not stuid:
        return -1
    info = select_one('select email,status from stuinfo where stuid=?', stuid)

    if info:
        info['stuid'] = stuid
        return info
    else:
        log.warn("unable to get {stuid}'s email status")
        return -1
Пример #7
0
def jiaowu(openid):
    stuid = get_stuid(openid)
    if not stuid:
        return -1
    info = select_one('select email,status from stuinfo where stuid=?', stuid)

    if info:
        info['stuid'] = stuid
        return info
    else:
        log.warn("unable to get {stuid}'s email status")
        return -1
Пример #8
0
def handle_history():
    if session.get('history_checked'): # 确认是否从history路由跳转过来
        page = int(request.args.get('page'))
        if not page:
            return redirect('')
        result = history_articles(get_stuid(session['openid']))
        article_list = []
        for i in result:
            if len(i):
                if PY2:
                    article_list.append({'title':i[1].encode('utf8'),'url':i[2].encode('utf8')})
                else:
                    article_list.append({'title': i[1], 'url': i[2]})
        article_list.reverse()
        if len(article_list)-page*8>8:
            result = {'result':article_list[(page-1)*8:8*page],'name':session['name']}
        else:
            result = {'result':article_list[(page-1)*8:],'name':session['name']}
    return jsonify(result)
Пример #9
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)
Пример #10
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)