|
# 导入Flask类
|
from flask import Flask
|
from flask import jsonify
|
from flask import request
|
from flask_cors import CORS
|
import pymssql
|
|
|
# Flask函数接收一个参数__name__,它会指向程序所在的包
|
app = Flask(__name__)
|
CORS(app, supports_credentials=True, resources=r'/*')
|
|
server = '192.168.0.123:1433'
|
user='sa'
|
password='admin123X'
|
database ='microseism3'
|
|
#根据月份获取数据
|
def get_event_location_data(month):
|
|
conn = pymssql.connect(server=server, user=user, password=password, database=database,as_dict=True)
|
cursor = conn.cursor()
|
res =[]
|
try:
|
sqlStr = 'SELECT * FROM dbo.event_location_'+ str(month)
|
# 执行查询语句或其他操作
|
cursor.execute(sqlStr)
|
|
# 获取结果集
|
result = cursor.fetchall()
|
|
for row in result:
|
dic={"x":row["Event_X"],"y":row["Event_Y"],"z":row["Event_Z"],"v":row["Event_Energy"]}
|
res.append(dic)
|
|
except Exception as e:
|
print("Error occurred:", str(e))
|
return []
|
|
finally:
|
# 关闭连接
|
cursor.close()
|
conn.close()
|
return res
|
|
#根据传入的月份查询数据
|
@app.route('/get_event_location_data', methods=['GET'])
|
def event_location_data():
|
month = request.args.get('month')
|
res = get_event_location_data(month)
|
return jsonify(res)
|
|
|
if __name__ == '__main__':
|
#app.run() # 可以指定运行的主机IP地址,端口,是否开启调试模式
|
app.run(host="192.168.0.107", port=8080)
|
|
|