-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (23 loc) · 829 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: UTF-8 -*-
"""
@Project :NewsReport
@File :main.py
@IDE :PyCharm
@Author :胖妞
@Date :2022/1/8 16:00
"""
import json
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
import uvicorn
app = FastAPI()
@app.get('/news/poster/{category}/{platform}')
def newsPoster(category: int, platform: int):
file_like = open('./output/%s_%s.jpg' % (category, platform), mode="rb")
return StreamingResponse(file_like, media_type="image/jpg")
@app.get('/news/text/{category}/{platform}')
def newsText(category: int, platform: int):
with open("./json/%s_%s.json" % (category, platform), 'r', encoding='utf-8') as load_f:
return json.load(load_f)
if __name__ == '__main__':
uvicorn.run(app='main:app', host="127.0.0.1", port=7890, reload=True, debug=True)