index.py 2.4 KB
Newer Older
梦想橡皮擦's avatar
梦想橡皮擦 已提交
1 2 3 4 5 6 7 8 9 10 11 12
import math

from flask import Blueprint, jsonify, request
from flask import render_template
from sqlalchemy import not_, and_, or_
from ..model import Csdn  # 导入上级模块

cs = Blueprint('csdn', __name__, url_prefix='/csdn')


@cs.route('/blogstar')
def user_list():
梦想橡皮擦's avatar
梦想橡皮擦 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    user = []
    page = request.args.get("page", 0)
    try:
        page = int(page)
    except Exception as e:
        return "what are you 弄啥嘞? <a href='/'>返回首页</a>", 403
    if page == 0:
        user = Csdn.query.order_by(-Csdn.totalScore).all()
    elif page == 1:
        user = Csdn.query.filter(Csdn.cateName == "IT其他").order_by(-Csdn.totalScore).all()
    elif page == 2:
        user = Csdn.query.filter(Csdn.cateName == "前端").order_by(-Csdn.totalScore).all()
    elif page == 3:
        user = Csdn.query.filter(Csdn.cateName == "后端").order_by(-Csdn.totalScore).all()

    elif page == 4:
        user = Csdn.query.filter(Csdn.cateName == "大数据与算法").order_by(-Csdn.totalScore).all()

    elif page == 5:
        user = Csdn.query.filter(Csdn.cateName == "云原生与云平台").order_by(-Csdn.totalScore).all()
    elif page == 6:
        user = Csdn.query.filter(Csdn.cateName == "前沿技术").order_by(-Csdn.totalScore).all()
    elif page == 7:
        user = Csdn.query.filter(Csdn.cateName == "人工智能").order_by(-Csdn.totalScore).all()
    elif page == 8:
        user = Csdn.query.filter(Csdn.cateName == "运维与安全").order_by(-Csdn.totalScore).all()
    elif page == 9:
        user = Csdn.query.filter(Csdn.cateName == "移动开发").order_by(-Csdn.totalScore).all()

    elif page == 10:
        user = Csdn.query.filter(Csdn.cateName == "物联网与嵌入式").order_by(-Csdn.totalScore).all()

梦想橡皮擦's avatar
梦想橡皮擦 已提交
45 46 47 48 49
    for u in user:
        if u.regtime is not None:
            u.star = "博客新星" if u.regtime.startswith("2022") else "博客之星"
        else:
            u.star = "---"
梦想橡皮擦's avatar
梦想橡皮擦 已提交
50 51 52

    bg_green = 200 if page == 0 else 10
    return render_template('csdn/blogstar.html', user=user,bg_green=bg_green)
梦想橡皮擦's avatar
梦想橡皮擦 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65


@cs.route('/newstar')
def new_star_list():
    user = Csdn.query.order_by(-Csdn.totalScore).filter(Csdn.regtime.startswith("2022")).all()
    return render_template('csdn/newstar.html', user=user)


@cs.route('/oldstar')
def old_star_list():
    user = Csdn.query.order_by(-Csdn.totalScore).filter(not_(Csdn.regtime.startswith("2022"))).all()

    return render_template('csdn/oldstar.html', user=user)