96 lines
2.5 KiB
Python
96 lines
2.5 KiB
Python
|
#!/usr/bin/python3
|
|||
|
# coding= utf-8
|
|||
|
|
|||
|
import sqlite3
|
|||
|
|
|||
|
|
|||
|
# @param text 文本
|
|||
|
# @return True:是,False:不是
|
|||
|
def __string(text):
|
|||
|
return True if isinstance(text, str) else False
|
|||
|
|
|||
|
|
|||
|
# 检查文本类型是否为浮点型
|
|||
|
# @param text 文本
|
|||
|
# @return True:是,False:不是
|
|||
|
def __float(text):
|
|||
|
if __string(text):
|
|||
|
try:
|
|||
|
return True if float("{0}".format(text)) else False
|
|||
|
except Exception:
|
|||
|
return False
|
|||
|
else:
|
|||
|
return True if isinstance(text, float) else False
|
|||
|
|
|||
|
|
|||
|
# 检查文本类型是否为浮点型
|
|||
|
# @param text 文本
|
|||
|
# @return True:是,False:不是
|
|||
|
def __int(text):
|
|||
|
if __string(text):
|
|||
|
try:
|
|||
|
return True if float("{0}".format(text)) else False
|
|||
|
except Exception:
|
|||
|
return False
|
|||
|
else:
|
|||
|
return True if isinstance(text, float) else False
|
|||
|
|
|||
|
|
|||
|
# 检查文本类型是否为数字型
|
|||
|
# @param text 文本
|
|||
|
# @return True:是,False:不是
|
|||
|
def __number(text):
|
|||
|
return True if re.search("[^0-9]", text) == None else False
|
|||
|
|
|||
|
|
|||
|
def func_year(s):
|
|||
|
print('func_year:', s)
|
|||
|
|
|||
|
|
|||
|
def func_month(s):
|
|||
|
print('func_month:', s)
|
|||
|
|
|||
|
|
|||
|
def create_data_collection_info_table():
|
|||
|
con = sqlite3.connect("../dms_client.db")
|
|||
|
cur = con.cursor()
|
|||
|
sql = "CREATE TABLE IF NOT EXISTS data_collection_info(id INTEGER PRIMARY KEY,collection_code TEXT,function_name TEXT,describe TEXT)"
|
|||
|
cur.execute(sql)
|
|||
|
# ①:添加单条数据
|
|||
|
data = "1,'Desire',5,'test'"
|
|||
|
cur.execute('INSERT INTO data_collection_info VALUES (%s)' % data)
|
|||
|
# ②:添加单条数据
|
|||
|
cur.execute("INSERT INTO data_collection_info values(?,?,?,?)", (6, "zgq", 20, 'test'))
|
|||
|
# ③:添加多条数据
|
|||
|
cur.executemany('INSERT INTO data_collection_info VALUES (?,?,?,?)',
|
|||
|
[(3, 'name3', 19, 'test'), (4, 'name4', 26, 'test')])
|
|||
|
cur.execute("UPDATE data_collection_info SET collection_code=? WHERE id=?", ('test1', 19))
|
|||
|
con.commit()
|
|||
|
# 关闭游标
|
|||
|
cur.close()
|
|||
|
# 断开数据库连接
|
|||
|
con.close()
|
|||
|
|
|||
|
|
|||
|
# 动态调用函数
|
|||
|
# @param tag 标签名
|
|||
|
# @param text 文本
|
|||
|
# @return True:OK, False:NG
|
|||
|
def item_check(func_name, text):
|
|||
|
if type and text:
|
|||
|
try:
|
|||
|
# 调用导入模块中的函数,并传参
|
|||
|
return eval("__{0}".format(func_name))(text)
|
|||
|
except Exception:
|
|||
|
return False
|
|||
|
else:
|
|||
|
return False
|
|||
|
|
|||
|
|
|||
|
if __name__ == '__main__':
|
|||
|
result = item_check("num", 123.23)
|
|||
|
print(result)
|
|||
|
strs = ['year', 'month']
|
|||
|
for s in strs:
|
|||
|
globals().get('func_%s' % s)(s)
|