Esempio n. 1
0
def search_title():
    try:
        data=request.get_json()
        title=data.get("title")
        page_info=data.get("page_info")
        page_size = page_info.get("page_size")
        page_num = page_info.get("page_num")
        allPageNum = Meeting_article.query.filter(
            Meeting_article.title.like("%" + title + "%")).count()
        pagination=Meeting_article.query.filter(
            Meeting_article.title.like("%"+title+"%"))\
            .order_by(Meeting_article.create_time.desc()).paginate(per_page=page_num,page=page_size)
        articles=pagination.items
        response_info=[]
        for i in articles:
            response_info.append({
                'id':i.id,
                'title':i.title,
                'create_time':i.create_time,
                'meeting_name':i.meeting_name,
                'authors':i.author,
                'abstract':i.abstract,
                'keyword':i.keyword,
                'address':i.address
            })
        return responseBody(data={'data':response_info,'allPageNum':allPageNum})

    except Exception as e:
        print(e)
        return responseError(Responses.PARAMETERS_ERROR)
Esempio n. 2
0
def getTop10():
    try:
        date=datetime.datetime.strptime('2020-01-01', '%Y-%m-%d')
        Articles=Meeting_article.query.filter_by(create_time=date).all()
        keywordDict={}
        for i in Articles:
            temp_list=list(i.keyword.split(';'))
            for j in temp_list:
                if (j not in keywordDict.keys()):
                    keywordDict[j]=1
                else:
                    keywordDict[j]+=1
        keywordDict['']=0
        keywordDict['暂无关键词']=0
        keyInfo=[]
        valueInfo=[]
        num=0
        i=0
        for k in sorted(keywordDict, key=keywordDict.__getitem__, reverse=True):
            if(i<10):
                keyInfo.append(k)
                valueInfo.append(keywordDict[k])
                num+=keywordDict[k]
                i+=1
        return responseBody(data=[{'key':keyInfo,'value':valueInfo,'num':num}])

    except Exception as e:
        print(e)
        return responseError(Responses.PARAMETERS_ERROR)
Esempio n. 3
0
def update_face():
    try:
        data = request.get_json()
        user_id=data.get("user_id")
        user_face=data.get("user_face")
        user = User.query.filter_by(id=user_id).first()
        user_avatar = "default.jpg"
        if user.avatar != "default":
            user_avatar = user.avatar
        avatar_filename = random_filename(user_avatar)

        user.avatar = avatar_filename
        db.session.commit()
        try:
            avatar_path = url_for('static', filename="avatars/%s" % avatar_filename)
            # 写入图片并保存
            with open(avatar_path, 'wb') as w:
                w.write(base64.b64decode(user_face))
            # 获得修改后的头像的base64编码
            with open(avatar_path, 'rb') as f:
                stream = base64.b64encode(f.read())
                avatar_base64_str = str(stream, encoding='utf-8')

            return responseBody(data=[{'avatar': avatar_base64_str}])
        except Exception as e:
            print(e)
            db.session.rollback()
            return responseError(Responses.SAVE_FILE_FAIL)

    except Exception as e:
        print(e)
        db.session.rollback()
        return responseError(Responses.PARAMETERS_ERROR)
Esempio n. 4
0
def getLineChart():
    try:
        Iccv_meeting=Meeting_article.query.filter_by(meeting_name='ICCV').all()
        ICCV_list=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        for i in Iccv_meeting:
            date=datetime.datetime.strftime(i.create_time,'%Y-%m-%d')
            if( int(2010) <= int(date[0:4]) and int( 2021)>=int(date[0:4]) ):
                ICCV_list[(int(date[0:4])-2010)]=ICCV_list[(int(date[0:4])-2010)]+1

        Cvpr_meeting=Meeting_article.query.filter_by(meeting_name='CVPR').all()
        CVPR_list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        for i in Cvpr_meeting:
            date=datetime.datetime.strftime(i.create_time,'%Y-%m-%d')
            if( int(2010) <= int(date[0:4]) and int( 2021)>=int(date[0:4]) ):
                CVPR_list[(int(date[0:4])-2010)]=CVPR_list[(int(date[0:4])-2010)]+1


        ECCV_list=[0,0,0,0,0,0,0,0,0,0,0,0]
        Eccv_meeting = Meeting_article.query.filter_by(meeting_name='ECCV').all()
        for i in Eccv_meeting:
            date=datetime.datetime.strftime(i.create_time,'%Y-%m-%d')
            if( int(2010) <= int(date[0:4]) and int( 2021)>=int(date[0:4]) ):
                # print(int(date[0:4]))
                ECCV_list[(int(date[0:4])-2010)]=ECCV_list[(int(date[0:4])-2010)]+1

        return responseBody(data=[{'ECCV':ECCV_list,'CVPR':CVPR_list,'ICCV':ICCV_list}])


    except Exception as e:
        print(e)
        return responseError(Responses.PARAMETERS_ERROR)
Esempio n. 5
0
def get_note():
    try:
        data=request.get_json()
        user_id=data.get("user_id")
        article_id=data.get("article_id")
        note=Note.query.filter_by(user_id=user_id,article_id=article_id).first()

        note_info=note.note
        return responseBody(data={'note_info':note_info})

    except Exception as e:
        print(e)
        return responseError(Responses.PARAMETERS_ERROR)
Esempio n. 6
0
def login():
    data = request.get_json()
    account = data.get("account")
    password = data.get("password")
    try:
        user = User.query.filter_by(account=account).first()
        # 用户不存在
        if not user:
            return responseError(Responses.NO_USER_FOUND)
        # 密码错误
        if not user.password == password:
            print(user.password)
            print(password)
            return responseError(Responses.INCORRECT_PASSWORD)
        # 生成token
        token = generate_token(user_id=user.id)
        session["token"] = token
        session["user_id"] = user.id
        # 获取用户头像路径
        user_avatar = "default.jpg"
        # if user.avatar != "default":
        #     user_avatar = user.avatar
        # avatar_path = url_for('static', filename="avatars/%s" % user_avatar)
        # 用户账号,姓名,当前时间
        account = user.account
        username = user.username
        if(user.gender==True):
            userGender="男"
        else:
            userGender="女"
        date = datetime.datetime.now()
        # 保存登录时间
        session["login_date"] = date
        # 获取加入天数
        day = date.day - user.create_time.day
        # 获得头像base64编码
        # with open(avatar_path, 'rb') as f:
        #     stream = base64.b64encode(f.read())
        #     avatar_base64_str = str(stream, encoding='utf-8')
            # 返回数据
        response_info = {
            "name": username,
            "userid": user.id,
            "token":str(token),
            "date": date.strftime("%Y-%m-%d %H:%M:%S"),
            "day": day
        }
        return responseBody(data=response_info)
    except Exception as e:
        print(e)
        return responseError(Responses.PARAMETERS_ERROR)
Esempio n. 7
0
def search_byfile():
    try:
        data = request.get_json()
        key_id = data.get('key_id')
        file_name = data.get('file_name')
        keyList = []
        with open(r"F:\寒假作业2\结队作业2\Team_work\static\userupload\%s" % file_name, 'r')as f:
            allKeyword = f.read()
            keyList = allKeyword.split(';')
            f.close()
            return responseBody(data={'keyInfo':keyList[key_id-1]})
    except Exception as e:
        print(e)
        return responseError(Responses.PARAMETERS_ERROR)
Esempio n. 8
0
def get_userInfo():
    try:
        data=request.get_json()
        user_id=data.get('user_id')
        user=User.query.filter_by(id=user_id).first()
        gender="男"
        if(user.gender==False):
            gender="女"
        user_info={'user_name':user.username,'user_gender':gender,'school':user.college,'password':user.password}
        return responseBody(data=user_info)

    except Exception as e:
        print(e)
        return responseError(Responses.PARAMETERS_ERROR)
Esempio n. 9
0
def upload_file():
    try:
        data=request.files.get('file')
        # print(data.read())
        filename = secure_filename(data.filename)
        # 生成文件保存路径
        save_path = r"F:\寒假作业2\结队作业2\Team_work\static\userupload\%s"%filename
        # 保存文件
        data.save(save_path)
        List=[]
        with open(save_path,'r')as f:
            List=f.read().split(';')
            f.close()

        return responseBody(data={'keyList':List})
    except Exception as e:
        print(e)
        return responseError(Responses.PARAMETERS_ERROR)
Esempio n. 10
0
def getRisingSUN():
    try:
        childrens=[]
        #ECCV
        eccvArticles=Meeting_article.query.filter_by(meeting_name='ECCV').all()
        eccvKeywordDict = {}
        for i in eccvArticles:
            temp_list = list(i.keyword.split(';'))
            for j in temp_list:
                if (j not in eccvKeywordDict.keys()):
                    eccvKeywordDict[j] = 1
                else:
                    eccvKeywordDict[j] += 1
        eccvKeywordDict[''] = 0
        eccvKeywordDict['暂无关键词'] = 0
        eccvNum=0
        valueInfo = []
        i = 0
        for k in sorted(eccvKeywordDict, key=eccvKeywordDict.__getitem__, reverse=True):
            if (i < 10):
                valueInfo.append({'name':k,'value':eccvKeywordDict[k]})
                eccvNum += eccvKeywordDict[k]
                i+=1

        childrens.append({'name':'EVVC','value':eccvNum,'children':valueInfo})


        #ICCV
        iccvArticles = Meeting_article.query.filter_by(meeting_name='ICCV').all()
        iccvKeywordDict = {}
        for i in iccvArticles:
            temp_list = list(i.keyword.split(';'))
            for j in temp_list:
                if (j not in iccvKeywordDict.keys()):
                    iccvKeywordDict[j] = 1
                else:
                    iccvKeywordDict[j] += 1
        iccvKeywordDict[''] = 0
        iccvKeywordDict['暂无关键词'] = 0
        iccvNum = 0
        valueInfo = []
        i = 0
        for k in sorted(iccvKeywordDict, key=iccvKeywordDict.__getitem__, reverse=True):
            if (i < 10):
                valueInfo.append({'name': k, 'value': iccvKeywordDict[k]})
                iccvNum += iccvKeywordDict[k]
                i += 1

        childrens.append({'name': 'ICCV', 'value': iccvNum, 'children': valueInfo})

        # CVPR
        cvprArticles = Meeting_article.query.filter_by(meeting_name='CVPR').all()
        cvprKeywordDict = {}
        for i in cvprArticles:
            temp_list = list(i.keyword.split(';'))
            for j in temp_list:
                if (j not in cvprKeywordDict.keys()):
                    cvprKeywordDict[j] = 1
                else:
                    cvprKeywordDict[j] += 1
        cvprKeywordDict[''] = 0
        cvprKeywordDict['暂无关键词'] = 0
        cvprNum = 0
        valueInfo = []
        i = 0
        for k in sorted(cvprKeywordDict, key=cvprKeywordDict.__getitem__, reverse=True):
            if (i < 10):
                valueInfo.append({'name': k, 'value': cvprKeywordDict[k]})
                cvprNum += cvprKeywordDict[k]
                i += 1

        childrens.append({'name': 'CVPR', 'value': cvprNum, 'children': valueInfo})


        return responseBody(data=childrens)
    except Exception as e:
        print(e)
        return responseError(Responses.PARAMETERS_ERROR)