-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
37 lines (27 loc) · 845 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
32
33
34
35
36
37
from flask import Flask, request, jsonify
from scheduled.topic_task import TopicTaskScheduled
from service.messages_service import MessageService
import os
import time
os.environ['TZ'] = 'Asia/Shanghai'
time.tzset()
app = Flask(__name__)
wxbot_service = MessageService()
@app.route('/')
def index():
return 'Hello World!'
@app.route('/api/robot-msg', methods=['POST', 'GET'])
def handle_post():
data = request.get_json()
if not data:
return jsonify({'error': 'No data provided'}), 400
try:
wxbot_service.get_messages(data)
return jsonify({'msg': 'ok'}), 200
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
# 初始化定时任务
TopicTaskScheduled.init_tasks()
# 启动服务
app.run(debug=False, host='0.0.0.0', port=12300)