Exemplo n.º 1
0
def get_read_info(nid, simple=False):
    send_stus = select_one('select stuids from noteindex where nid=?', nid)
    if not send_stus:
        return None
    if(',' in send_stus['stuids']):
        stu_send_list = send_stus['stuids'].split(',')[:-1]
    else:
        stu_send_list = [send_stus['stuids']]
    stu_send_list = list(set(stu_send_list))
    if simple:
        read_number = select_int('select readpop from noteresponse where nid=?', nid)
        if read_number is None:
            read_number=0
        return {'read_list': read_number, 'unread_list': len(stu_send_list)-read_number}

    read_info = select_one('select readTime from noteresponse where nid=?', nid)
    if not read_info:
        return None

    stu_read_list = [i.split(':')[0] for i in read_info['readtime'].split(',')[:-1]]
    stu_read_dicts_with_time = [{'stuid': i.split(":")[0],
                                 'time': __transfer_time(i.split(':')[1]),
                                 'name': get_stu_name(i.split(":")[0])} for i in read_info['readtime'].split(',')[:-1]]

    unread_stu = []
    for i in stu_send_list:
        if i in stu_read_list:
            pass
        else:
            unread_stu.append({'stuid':i, 'name':get_stu_name(i)})
    return {'read_list': stu_read_dicts_with_time, 'unread_list': unread_stu}
Exemplo n.º 2
0
def get_stu_name(stuid=None, openid=None, first=True):
    if first:
        name = select_one('select name from stuinfo where stuid = ?', stuid)
    else:
        name = select_one('select name from stuinfo where stuid=(select stuid from biding where openid = ?)', openid)

    if name:
        return name['name']
    else:
        return None
Exemplo n.º 3
0
    def get_gpa(self):
        if self.stuid != -1:
            your_gpa = select_one('select *from creditcur where StuID = ?',
                                  self.stuid)

            if not your_gpa:
                return "当前没有您的GPA信息!!"
            if your_gpa.get('gpa'):
                self.gpa = round(your_gpa['gpa'], 4)
                self.Class = your_gpa['class']
                self.gpa_rank = your_gpa['rank']
                self.gpa_rank_next = self.gpa_rank + 1
                self.gpa_rank_prev = self.gpa_rank - 1

                max_rank = select_int(
                    'select max(rank) as max_rank from creditcur where class = ?',
                    self.Class)

                your_gpa['max'] = max_rank
                if self.gpa_rank != max_rank:
                    next_gpa = select_one(
                        'select *from creditcur where Class = ? and rank= ?',
                        self.Class, self.gpa_rank_next)
                    if next_gpa is None:
                        self.gpa_rank_next += 1
                        next_gpa = select_one(
                            'select *from creditcur where Class = ? and rank= ?',
                            self.Class, self.gpa_rank_next)
                    your_gpa['next'] = next_gpa['gpa']
                else:
                    your_gpa['nonnext'] = 1  # 排名是否最后的标志位
                    your_gpa['next'] = '悲剧…后面没有了'

                if self.gpa_rank_prev != 0:
                    prev_gpa = select_one(
                        'select *from creditcur where Class = ? and rank= ?',
                        self.Class, self.gpa_rank_prev)

                    your_gpa['prev'] = prev_gpa['gpa']
                else:
                    your_gpa['nonprev'] = 1
                    your_gpa['prev'] = '很强!前面木有了'

                first_gpa = select_one(
                    'select *from creditcur where Class = ? and rank= ?',
                    self.Class, 1)

                your_gpa['first'] = first_gpa['gpa']

                return your_gpa
            else:
                return '您没有记录在案的GPA数据!'
        else:
            return "您尚未绑定学号!"
Exemplo n.º 4
0
def get_stu_name(stuid=None, openid=None, first=True):
    if first:
        name = select_one('select name from stuinfo where stuid = ?', stuid)
    else:
        name = select_one(
            'select name from stuinfo where stuid=(select stuid from biding where openid = ?)',
            openid)

    if name:
        return name['name']
    else:
        return None
Exemplo n.º 5
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 "您尚未绑定学号!"
Exemplo n.º 6
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 "您尚未绑定学号!"
Exemplo n.º 7
0
def get_openid(stuid):
    openid = select_one('select openid from biding where stuid = ?', stuid)

    if openid:
        return openid['openid']
    else:
        return None
Exemplo n.º 8
0
def get_openid(stuid):
    openid = select_one('select openid from biding where stuid = ?', stuid)

    if openid:
        return openid['openid']
    else:
        return None
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
0
    def get_gpa(self):
        if self.stuid != -1:
            your_gpa = select_one('select *from creditcur where StuID = ?', self.stuid)

            if not your_gpa:
                return "当前没有您的GPA信息!!"
            if your_gpa.get('gpa'):
                self.gpa = round(your_gpa['gpa'], 4)
                self.Class = your_gpa['class']
                self.gpa_rank = your_gpa['rank']
                self.gpa_rank_next = self.gpa_rank + 1
                self.gpa_rank_prev = self.gpa_rank - 1

                max_rank = select_int('select max(rank) as max_rank from creditcur where class = ?',self.Class)

                your_gpa['max'] = max_rank
                if self.gpa_rank != max_rank:
                    next_gpa = select_one('select *from creditcur where Class = ? and rank= ?', self.Class, self.gpa_rank_next)
                    if next_gpa is None:
                        self.gpa_rank_next += 1
                        next_gpa = select_one('select *from creditcur where Class = ? and rank= ?', self.Class, self.gpa_rank_next)
                    your_gpa['next'] = next_gpa['gpa']
                else:
                    your_gpa['nonnext'] = 1   # 排名是否最后的标志位
                    your_gpa['next'] = '悲剧…后面没有了'

                if self.gpa_rank_prev != 0:
                    prev_gpa = select_one('select *from creditcur where Class = ? and rank= ?', self.Class, self.gpa_rank_prev)

                    your_gpa['prev'] = prev_gpa['gpa']
                else:
                    your_gpa['nonprev'] = 1
                    your_gpa['prev'] = '很强!前面木有了'

                first_gpa = select_one('select *from creditcur where Class = ? and rank= ?', self.Class, 1)

                your_gpa['first'] = first_gpa['gpa']

                return your_gpa
            else:
                return '您没有记录在案的GPA数据!'
        else:
            return "您尚未绑定学号!"
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 14
0
def get_read_info(nid, simple=False):
    send_stus = select_one('select stuids from noteindex where nid=?', nid)
    if not send_stus:
        return None
    if (',' in send_stus['stuids']):
        stu_send_list = send_stus['stuids'].split(',')[:-1]
    else:
        stu_send_list = [send_stus['stuids']]
    stu_send_list = list(set(stu_send_list))
    if simple:
        read_number = select_int(
            'select readpop from noteresponse where nid=?', nid)
        if read_number is None:
            read_number = 0
        return {
            'read_list': read_number,
            'unread_list': len(stu_send_list) - read_number
        }

    read_info = select_one('select readTime from noteresponse where nid=?',
                           nid)
    if not read_info:
        return None

    stu_read_list = [
        i.split(':')[0] for i in read_info['readtime'].split(',')[:-1]
    ]
    stu_read_dicts_with_time = [{
        'stuid': i.split(":")[0],
        'time': __transfer_time(i.split(':')[1]),
        'name': get_stu_name(i.split(":")[0])
    } for i in read_info['readtime'].split(',')[:-1]]

    unread_stu = []
    for i in stu_send_list:
        if i in stu_read_list:
            pass
        else:
            unread_stu.append({'stuid': i, 'name': get_stu_name(i)})
    return {'read_list': stu_read_dicts_with_time, 'unread_list': unread_stu}
Exemplo n.º 15
0
 def get_routine_appraise(self):
     if self.stuid != -1:
         routine = select_one('select *from routine_appraise_13 where stuid = ?',self.stuid)
         if not routine:
             return "当前没有您的日常行为考核信息!"
         self.routine_base = routine['base']
         self.routine_encou = routine['encourage']
         self.routine_develop = routine['develop']
         self.routine = self.routine_base + self.routine_encou + self.routine_develop
         self.routine_rank = routine['rank']
         routine['total'] = self.routine
         return routine
     else:
         return "您尚未绑定学号!"
Exemplo n.º 16
0
 def get_routine_appraise(self):
     if self.stuid != -1:
         routine = select_one(
             'select *from routine_appraise_13 where stuid = ?', self.stuid)
         if not routine:
             return "当前没有您的日常行为考核信息!"
         self.routine_base = routine['base']
         self.routine_encou = routine['encourage']
         self.routine_develop = routine['develop']
         self.routine = self.routine_base + self.routine_encou + self.routine_develop
         self.routine_rank = routine['rank']
         routine['total'] = self.routine
         return routine
     else:
         return "您尚未绑定学号!"
Exemplo n.º 17
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
Exemplo n.º 18
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