【国产RISC-V Linux板 昉·星光VisionFive试用报告】Tornado 数据写入读取
[复制链接]
中午写好了数据插入,晚餐后继续写数据读取:
elif data_quest['command'] == "getPersonnel":
if 'phone' in data_quest:
print("按手机号码查询")
results = personnel_information.get(personnel_information.phone == data_quest['phone'])
elif 'ID_card' in data_quest:
results = personnel_information.get(personnel_information.ID_card == data_quest['ID_card'])
print("按身份证查询")
else:
res['code'] = 2004
res['msg'] = "查询字段不对"
if res['msg'] == "":
if results:
res['name'] = results.name
res['phone'] = results.phone
res['ID_card'] = results.ID_card
res['uint'] = results.uint
res['code'] = 1000
res['msg'] = "get success"
else:
res['code'] = 2005
res['msg'] = "get failed"
然后建立测试函数net_test.py:
# -*- coding: utf-8 -*-
import urllib3
import json
url = "http://192.168.3.192:9000/man"
http = urllib3.PoolManager()
class sampleNet:
def post(self, dict_info):
try:
encoded_data = json.dumps(dict_info).encode("gbk")
resp = http.request(
"POST",
url,
body=encoded_data,
headers={
'x-env-code': 'mafutian',
'content-type': 'application/json;charset=gbk'
}
)
return resp
except Exception as e:
print("post ERR:" + str(e))
def test():
net_post = sampleNet()
data = {"command": "appendPersonnel", "name": "测试四", "phone": "13788547701", "ID_card": "450329199001011132",
"uint": "测试单位"}
try:
resp = net_post.post(data)
if resp.status == 200:
data = json.loads(resp.data)
print(data)
except Exception as e:
print(e)
def get():
net_post = sampleNet()
data = {"command": "getPersonnel", "phone": "13788547709"}
try:
resp = net_post.post(data)
if resp.status == 200:
data = json.loads(resp.data)
print(data)
except Exception as e:
print(e)
if __name__ == "__main__":
# test()
get()
运行test()是插入函数:
然后运行获取数据:
到此对被采样人的信息保存、获取都测试通过了,下一步还有采样机构等的信息,处理起来就比较复杂。明天测试串口屏展示采样人的信息保存、查询。
|