tianruci commited on
Commit
8dd3039
·
verified ·
1 Parent(s): 2ca81a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -38
app.py CHANGED
@@ -128,41 +128,3 @@ async def get_trending(num: int = 10):
128
  "cache_expires_in": CACHE_EXPIRY.total_seconds(),
129
  "rate_limit_info": "Consider adding a GitHub token for higher rate limits"
130
  }
131
-
132
- @app.get("/trending/stream")
133
- async def stream_trending(interval: int = 60, client_id: str = None):
134
- """增强版 SSE 端点"""
135
- async def event_generator():
136
- try:
137
- while True:
138
- # 发送心跳
139
- yield "event: heartbeat\ndata: \n\n"
140
-
141
- # 获取数据
142
- if not last_updated or (datetime.now() - last_updated) > timedelta(seconds=interval):
143
- await fetch_github_trending()
144
-
145
- data = {
146
- "trending": cached_trending[:10],
147
- "last_updated": last_updated.isoformat() if last_updated else None,
148
- "client_id": client_id,
149
- "next_update": (datetime.now() + timedelta(seconds=interval)).isoformat()
150
- }
151
- yield f"event: update\ndata: {json.dumps(data)}\n\n"
152
-
153
- await asyncio.sleep(interval)
154
-
155
- except asyncio.CancelledError:
156
- print(f"客户端断开连接: {client_id}")
157
- except Exception as e:
158
- print(f"SSE 错误: {e}")
159
-
160
- return StreamingResponse(
161
- event_generator(),
162
- media_type="text/event-stream",
163
- headers={
164
- "Cache-Control": "no-cache",
165
- "Connection": "keep-alive",
166
- "X-Accel-Buffering": "no"
167
- }
168
- )
 
128
  "cache_expires_in": CACHE_EXPIRY.total_seconds(),
129
  "rate_limit_info": "Consider adding a GitHub token for higher rate limits"
130
  }