优化代码
This commit is contained in:
parent
54b723fefd
commit
36b33e782c
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
19
run.py
19
run.py
@ -1,11 +1,12 @@
|
||||
from flask import Flask
|
||||
from fastapi import FastAPI
|
||||
import uvicorn
|
||||
from utils import query_weather
|
||||
from utils.log import Log
|
||||
|
||||
app = Flask(__name__)
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.route('/weather', methods=['GET'])
|
||||
@app.get('/weather')
|
||||
def weather():
|
||||
log = Log().getlog()
|
||||
response = query_weather.query_weather()
|
||||
@ -14,7 +15,7 @@ def weather():
|
||||
return response, 200
|
||||
|
||||
|
||||
@app.route('/weather_all', methods=['GET'])
|
||||
@app.get('/weather_all')
|
||||
def weather_all():
|
||||
log = Log().getlog()
|
||||
response = query_weather.query_weather(extensions='all')
|
||||
@ -23,7 +24,7 @@ def weather_all():
|
||||
return response, 200
|
||||
|
||||
|
||||
@app.route('/weather_flag', methods=['GET'])
|
||||
@app.get('/weather_flag')
|
||||
def weather_flag():
|
||||
log = Log().getlog()
|
||||
response = query_weather.query_weather()
|
||||
@ -31,10 +32,12 @@ def weather_flag():
|
||||
weather = response['lives'][0]['weather']
|
||||
# weather包含雨字符串
|
||||
if '雨' in weather:
|
||||
return {"weather":1}, 200
|
||||
log.info({"weather": 1})
|
||||
return {"weather": 1}, 200
|
||||
else:
|
||||
return {"weather":0}, 200
|
||||
log.info({"weather": 0})
|
||||
return {"weather": 0}, 200
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=1314, debug=False)
|
||||
uvicorn.run(app='main:app', host='0.0.0.0', port=1314, reload=True)
|
||||
|
@ -1,40 +0,0 @@
|
||||
from flask import Flask, render_template, request, jsonify
|
||||
from utils.sql_parse import parse_create_table_sql
|
||||
from utils.log import Log
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
log = Log().getlog()
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/convert', methods=['POST'])
|
||||
def convert_sql():
|
||||
|
||||
sql_input = request.form['sql']
|
||||
if sql_input.strip()=='':
|
||||
|
||||
return jsonify({
|
||||
'parsed_result': "请在上面输入框输入hologres建表语句",
|
||||
'message': 'SQL processed.'
|
||||
})
|
||||
|
||||
hologres_connection = request.form['hologresConnection']
|
||||
log.info("SQL Input: %s", sql_input)
|
||||
log.info("SQL hologres_connection: %s", hologres_connection)
|
||||
try:
|
||||
parsed_result=parse_create_table_sql(sql_input,hologres_connection)
|
||||
result = {
|
||||
'parsed_result': parsed_result,
|
||||
'message': 'SQL processed successfully.'
|
||||
}
|
||||
except Exception as e:
|
||||
result = {'error': f'请检查输入sql:\n\n {str(e)}'}
|
||||
log.info("SQL result: %s", result)
|
||||
return jsonify(result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 指定host和port,这里使用0.0.0.0可以让服务器被外部访问
|
||||
app.run(host='0.0.0.0', port=8778, debug=True)
|
Loading…
x
Reference in New Issue
Block a user