feat: 创建 FastAPI 项目骨架(config + main + 依赖管理)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from typing import List
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
|
||||
|
||||
# 应用
|
||||
debug: bool = False
|
||||
log_level: str = "INFO"
|
||||
|
||||
# 数据库
|
||||
database_url: str = "postgresql+asyncpg://gx-gp-notify:password@localhost:5432/gx-gp-notify"
|
||||
|
||||
# 爬虫
|
||||
crawler_base_url: str = "https://zfcg.gxzf.gov.cn"
|
||||
crawler_keywords: List[str] = ["大化"]
|
||||
crawler_max_pages: int = 10
|
||||
crawler_timeout: int = 30
|
||||
crawler_page_size: int = 100
|
||||
|
||||
# 企业微信
|
||||
wechat_enabled: bool = True
|
||||
wechat_corp_id: str = ""
|
||||
wechat_agent_id: str = ""
|
||||
wechat_secret: str = ""
|
||||
wechat_token: str = ""
|
||||
wechat_encoding_aes_key: str = ""
|
||||
wechat_port: int = 18001
|
||||
wechat_host: str = "0.0.0.0"
|
||||
|
||||
# 定时任务
|
||||
scheduler_enabled: bool = True
|
||||
scheduler_cron: str = "0 8,14,18 * * *"
|
||||
|
||||
# Markdown
|
||||
markdown_enabled: bool = True
|
||||
markdown_output_file: str = "onu.md"
|
||||
|
||||
# 公告来源(JSON 字符串,从环境变量读取)
|
||||
announcement_sources: str = '{"ZcyAnnouncement1":{"category_id":66485,"name":"采购公告","type":"purchase"},"ZcyAnnouncement2":{"category_id":66485,"name":"结果公告","type":"result"},"ZcyAnnouncement3":{"category_id":66485,"name":"合同公告","type":"contract"},"ZcyAnnouncement4":{"category_id":66485,"name":"更正公告","type":"correction"},"ZcyAnnouncement5":{"category_id":66485,"name":"招标文件预公示","type":"pre_announcement"},"ZcyAnnouncement6":{"category_id":66485,"name":"单一来源公示","type":"single_source"},"ZcyAnnouncement7":{"category_id":66485,"name":"电子卖场公示","type":"electronic_market"},"ZcyAnnouncement10":{"category_id":66485,"name":"履约验收公示","type":"acceptance"},"ZcyAnnouncement11":{"category_id":66485,"name":"工程类公告","type":"engineering"},"ZcyAnnouncement20":{"category_id":66485,"name":"框架协议征集公告","type":"framework_agreement"},"ZcyAnnouncement21":{"category_id":66485,"name":"框架协议入围结果公告","type":"framework_result"},"ZcyAnnouncement23":{"category_id":66485,"name":"框架协议成交结果汇总公告","type":"framework_summary"},"61-266648":{"category_id":66485,"name":"采购意向公开","type":"intention"}}'
|
||||
|
||||
|
||||
settings = Settings()
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from app.config import settings
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
logging.basicConfig(
|
||||
level=getattr(logging, settings.log_level),
|
||||
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
||||
)
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="广西政府采购网公告监控系统",
|
||||
version="2.0.0",
|
||||
lifespan=lifespan,
|
||||
docs_url="/docs" if settings.debug else None,
|
||||
redoc_url=None,
|
||||
)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {"status": "ok"}
|
||||
Reference in New Issue
Block a user