main
HuangHai 1 week ago
parent 55d310f014
commit 054da48991

@ -295,5 +295,91 @@ async def render_html(request: fastapi.Request):
}
@app.get("/api/sources")
async def get_sources(page: int = 1, limit: int = 10):
try:
pg_pool = await init_postgres_pool()
async with pg_pool.acquire() as conn:
# 获取总数
total = await conn.fetchval("SELECT COUNT(*) FROM t_wechat_source")
# 获取分页数据
offset = (page - 1) * limit
rows = await conn.fetch(
"""
SELECT id, account_id,account_name, created_at
FROM t_wechat_source
ORDER BY created_at DESC
LIMIT $1 OFFSET $2
""",
limit, offset
)
sources = [
{
"id": row[0],
"name": row[1],
"type": row[2],
"update_time": row[3].strftime("%Y-%m-%d %H:%M:%S") if row[3] else None
}
for row in rows
]
return {
"code": 0,
"data": {
"list": sources,
"total": total,
"page": page,
"limit": limit
}
}
except Exception as e:
return {"code": 1, "msg": str(e)}
@app.get("/api/articles")
async def get_articles(page: int = 1, limit: int = 10):
try:
pg_pool = await init_postgres_pool()
async with pg_pool.acquire() as conn:
# 获取总数
total = await conn.fetchval("SELECT COUNT(*) FROM t_wechat_articles")
# 获取分页数据
offset = (page - 1) * limit
rows = await conn.fetch(
"""
SELECT a.id, a.title, a.source as source as name,
a.publish_time, a.collection_time
FROM t_wechat_articles a
ORDER BY a.collection_time DESC
LIMIT $1 OFFSET $2
""",
limit, offset
)
articles = [
{
"id": row[0],
"title": row[1],
"source": row[2],
"publish_date": row[3].strftime("%Y-%m-%d") if row[3] else None,
"collect_time": row[4].strftime("%Y-%m-%d %H:%M:%S") if row[4] else None
}
for row in rows
]
return {
"code": 0,
"data": {
"list": articles,
"total": total,
"page": page,
"limit": limit
}
}
except Exception as e:
return {"code": 1, "msg": str(e)}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)

@ -177,7 +177,7 @@
<body>
<div class="container">
<h1>【长春市教育信息资讯库】</h1>
<center><a href="ChangChunManager.html"><h3>资讯库维护</h3></a></center>
<center><a href="ChangChunManager.html" target="_blank"><h3>资讯库维护</h3></a></center>
<div class="data-area" id="answerArea">
<div style="color:#666; padding:20px; text-align:center;">
<p>请在下方输入您的问题,答案将在此处显示</p>

@ -3,14 +3,14 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>长春市信息资讯库管理系统</title>
<title>长春市教育信息资讯库维护</title>
<link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
<div class="layui-container">
<div class="layui-row">
<div class="layui-col-md12">
<h2 class="layui-header">长春市信息资讯库管理系统</h2>
<h2 class="layui-header">长春市教育信息资讯库维护</h2>
</div>
</div>
@ -43,8 +43,8 @@
page: true,
cols: [[
{field: 'id', title: 'ID', width:80},
{field: 'name', title: '来源名称'},
{field: 'type', title: '类型'},
{field: 'name', title: '称'},
{field: 'type', title: '名称'},
{field: 'update_time', title: '更新时间'}
]]
});

Loading…
Cancel
Save