Commit 57a2af4d by 潘建波

添加code服务

1 parent 37a56c8b
#!/usr/bin/evn python
# coding=utf-8
from flask import Blueprint,request,redirect,url_for
import flask
import apps.gbvar.database_global as dbs
import json,re,time,io
code_sev = Blueprint('code_sev', __name__)
# event_types
@code_sev.route('/codes/event_types', methods=["GET"])
def geteventtypes():
con = dbs.get_value()
cur = con.cursor()
sql_select = 'select * from tb_event_types'
cur.execute(sql_select)
result = []
for item in cur:
dict = {
'event_type_unid': item[0],
'event_cate_unid':item[1],
'code':item[2],
'name':item[3]
}
result.append(dict)
res = flask.make_response(json.dumps(result, encoding="UTF-8", ensure_ascii=False, sort_keys=False, indent=4).encode('utf-8'))
res.headers['Access-Control-Allow-Origin'] = '*'
res.headers['Access-Control-Allow-Methods'] = 'POST,GET,OPTIONS'
res.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
return res
#traffic_cates
@code_sev.route('/traffic/cates', methods=["GET"])
def gettrafficcate():
con = dbs.get_value()
cur = con.cursor()
sql_select = 'select * from tb_traffic_cate'
cur.execute(sql_select)
result = []
for item in cur:
dict = {
'cate_unid':item[0],
'cate_code':item[1],
'name':item[2],
'note':item[3]
}
result.append(dict)
res = flask.make_response(json.dumps(result, encoding="UTF-8", ensure_ascii=False, sort_keys=False, indent=4).encode('utf-8'))
res.headers['Access-Control-Allow-Origin'] = '*'
res.headers['Access-Control-Allow-Methods'] = 'POST,GET,OPTIONS'
res.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
return res
#traffic_types
@code_sev.route('/traffic/cates/<string:cate_unid>/codes',methods=["GET"])
def gettrafficcodes(cate_unid):
con = dbs.get_value()
cur = con.cursor()
sql_select = "select * from tb_traffic_type where cate = '%s'"%(cate_unid)
print (sql_select)
cur.execute(sql_select)
result = []
for item in cur:
dict = {
'cate_unid': item[0],
'code': item[2],
'name': item[3]
}
result.append(dict)
res = flask.make_response(json.dumps(result, encoding="UTF-8", ensure_ascii=False, sort_keys=False, indent=4).encode('utf-8'))
res.headers['Access-Control-Allow-Origin'] = '*'
res.headers['Access-Control-Allow-Methods'] = 'POST,GET,OPTIONS'
res.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
return res
......@@ -24,7 +24,8 @@ def dataRecv():
res = etl.eventToLocal.saveEventToLocal(dataDic)
print(res)
send_all_data(sv_global.get_value(),data)
#存入本地数据库
push_dbs(data)
else:
print('error: data to dict failed, data:{}'.format(data))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!