Files
kami_walmart_card/app.py
2025-03-21 00:17:37 +08:00

48 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import logging
from logging.handlers import TimedRotatingFileHandler
from flask import Flask, request
from flask_cors import CORS
from spiders import WalMartCardSpider
app = Flask(__name__)
# 跨域
CORS(app)
# 设置日志记录级别,可以根据需要调整
app.logger.setLevel(logging.INFO)
# 创建按天滚动的日志处理程序
log_file = 'walmart_bind.log'
handler = TimedRotatingFileHandler(log_file, when='midnight', interval=1, backupCount=7, encoding="utf-8")
handler.suffix = '%Y-%m-%d.log' # 日志文件名的后缀格式,这里按日期命名
handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
app.logger.addHandler(handler)
@app.route('/walmart/bind/card', methods=['GET', 'POST'], strict_slashes=False)
def hello_world():
if request.method == 'GET':
return 'okk'
elif request.method == 'POST':
# 接收参数
data = json.loads(request.get_data())
card_num = data.get("card_num")
cookies = data.get("cookies")
card_pwd = data.get("card_pwd")
order_num = data.get("order_num")
# 日志打印
app.logger.info(f"订单ID{order_num},请求参数:{data}")
res = WalMartCardSpider(
cookies=cookies,
card_num=card_num,
card_pwd=card_pwd,
order_num=order_num,
app=app
).run()
return res
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5009)