index.py 5.2 KB
Newer Older
梦想橡皮擦's avatar
梦想橡皮擦 已提交
1 2 3 4
import math

from flask import Blueprint, jsonify, request
from flask import render_template
5
from sqlalchemy import not_, and_, or_, text
梦想橡皮擦's avatar
梦想橡皮擦 已提交
6

梦想橡皮擦's avatar
梦想橡皮擦 已提交
7
from ..model import Csdn  # 导入上级模块
梦想橡皮擦's avatar
梦想橡皮擦 已提交
8
from app import db
梦想橡皮擦's avatar
梦想橡皮擦 已提交
9 10

cs = Blueprint('csdn', __name__, url_prefix='/csdn')
11 12
nav = dict();
nav['csdn'] = 'active'
梦想橡皮擦's avatar
梦想橡皮擦 已提交
13 14 15 16


@cs.route('/blogstar')
def user_list():
梦想橡皮擦's avatar
梦想橡皮擦 已提交
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 45 46 47 48
    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
梦想橡皮擦 已提交
49 50 51 52 53
    for u in user:
        if u.regtime is not None:
            u.star = "博客新星" if u.regtime.startswith("2022") else "博客之星"
        else:
            u.star = "---"
梦想橡皮擦's avatar
梦想橡皮擦 已提交
54 55

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


@cs.route('/newstar')
def new_star_list():
    user = Csdn.query.order_by(-Csdn.totalScore).filter(Csdn.regtime.startswith("2022")).all()
62
    return render_template('csdn/newstar.html', user=user, nav=nav)
梦想橡皮擦's avatar
梦想橡皮擦 已提交
63 64


梦想橡皮擦's avatar
梦想橡皮擦 已提交
65 66 67 68 69 70 71 72 73 74 75 76
@cs.route('/zong')
def zong_star_list():
    user = []
    t = request.args.get("t", 0)
    try:
        t = int(t)
    except Exception as e:
        return "what are you 弄啥嘞? <a href='/'>返回首页</a>", 403

    if t == 0:
        user = Csdn.query.order_by(-Csdn.totalScore).all()

77
    elif t == 1:
梦想橡皮擦's avatar
梦想橡皮擦 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
        user = Csdn.query.order_by(-Csdn.yuanli).all()
    elif t == 2:
        user = Csdn.query.order_by(-Csdn.fensi).all()
    elif t == 3:
        user = Csdn.query.order_by(-Csdn.fangwen).all()
    elif t == 4:
        user = Csdn.query.order_by(-Csdn.yuanchuang).all()
    elif t == 5:
        user = Csdn.query.order_by(Csdn.zongbang).all()
    elif t == 6:
        user = Csdn.query.order_by(-Csdn.tie).all()
    elif t == 7:
        # sql  = "SELECT * FROM score ORDER BY CONVERT(ip USING gbk) DESC"
        sql = "SELECT * FROM score ORDER BY CONVERT(ip USING gbk) DESC"
        result = db.engine.execute(text(sql))
        user = [row for row in result]
    """
<a class="btn btn-success" href="/csdn/zong?t=1">按原力排名</a>
<a class="btn btn-success" href="/csdn/zong?t=2">按粉丝排名</a>
<a class="btn btn-success" href="/csdn/zong?t=3">按访问数排名</a>
<a class="btn btn-success" href="/csdn/zong?t=4">按文章数排名</a>
<a class="btn btn-success" href="/csdn/zong?t=5">按总榜数排名</a>
<a class="btn btn-success" href="/csdn/zong?t=6">按铁粉数排名</a>
<a class="btn btn-success" href="/csdn/zong?t=7">按省市排序</a>
    """
梦想橡皮擦's avatar
梦想橡皮擦 已提交
103

104
    return render_template('csdn/blogstar_d.html', user=user, nav=nav)
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152


from datetime import date, timedelta


@cs.route('/rank')
def column():
    yesterday = (date.today() + timedelta(days=-1)).strftime("%Y-%m-%d")

    sql = text(f"""select * from (
select zhuanlan_user,sum(price) as total,count(id) as ren from subscribe where subscribe_time like '{yesterday}%'
GROUP BY zhuanlan_user
ORDER BY total desc 
limit 50
) abc 
LEFT JOIN zhuanlan z ON z.userName = abc.zhuanlan_user""")

    result = db.engine.execute(sql)
    data = result.fetchall()
    nav['csdn'] = ''
    nav['csdn_col'] = 'active'
    return render_template('csdn/rank.html', data=data, nav=nav, yesterday=yesterday)


@cs.route('/m_rank')
def m_column():
    yesterday = (date.today() + timedelta(days=-1)).strftime("%Y-%m")

    sql = text(f"""select * from (
select zhuanlan_user,sum(price) as total,count(id) as ren from subscribe where subscribe_time like '{yesterday}%'
GROUP BY zhuanlan_user
ORDER BY total desc 
limit 50
) abc 
LEFT JOIN zhuanlan z ON z.userName = abc.zhuanlan_user""")

    result = db.engine.execute(sql)
    data = result.fetchall()

    sql2 = text(f"""
    select title,count(id) n from subscribe where subscribe_time like '{yesterday}%' GROUP BY title
ORDER BY n desc limit 10 """)
    result2 = db.engine.execute(sql2)
    data2 = result2.fetchall()

    nav['csdn'] = ''
    nav['csdn_col'] = 'active'
    return render_template('csdn/m_rank.html', data=data, nav=nav, yesterday=yesterday, hot_col=data2)