feat: tweet detail server api

master
wlt233 2 weeks ago
parent f909dffe64
commit 381816bbad

@ -3,6 +3,7 @@
"email": "114514@1919.com", "email": "114514@1919.com",
"password": "810810", "password": "810810",
"url": "127.0.0.1:7237",
"callback_url": "http://localhost:1145", "callback_url": "http://localhost:1145",
"proxy": "socks5://localhost:7890", "proxy": "socks5://localhost:7890",

@ -8,7 +8,9 @@ from apscheduler.triggers.interval import IntervalTrigger
from loguru import logger from loguru import logger
from quart import Quart, jsonify, request from quart import Quart, jsonify, request
from src.twi_api import get_detail
from src.twitter import task_handler from src.twitter import task_handler
from src.twi_parser import parse_detail
app = Quart(__name__) app = Quart(__name__)
scheduler = AsyncIOScheduler() scheduler = AsyncIOScheduler()
@ -64,14 +66,31 @@ async def list_task():
@app.route("/tweet/detail", methods=["GET"])
async def tweet_detail():
tweet_id = request.args.get("tweet_id")
if not tweet_id:
return jsonify({"error": "tweet_id is required"}), 400
try:
data = await get_detail(tweet_id)
data = parse_detail(data)
return jsonify(data)
except Exception as e:
logger.error(f"Tweet detail api error: {e}")
return jsonify({"error": str(e)}), 500
if __name__ == "__main__": if __name__ == "__main__":
import asyncio import asyncio
from hypercorn.asyncio import serve from hypercorn.asyncio import serve
from hypercorn.config import Config from hypercorn.config import Config
with open("./config/config.json", "r", encoding="utf-8") as f: conf = json.load(f)
config = Config() config = Config()
config.bind = ["127.0.0.1:7217"] config.bind = [conf["url"]]
config.accesslog = logging.getLogger('hypercorn.access') config.accesslog = logging.getLogger('hypercorn.access')
config.errorlog = logging.getLogger('hypercorn.error') config.errorlog = logging.getLogger('hypercorn.error')
asyncio.run(serve(app, config)) asyncio.run(serve(app, config))

Loading…
Cancel
Save