Commit 4573d2bb authored by 张彦钊's avatar 张彦钊

add test.py for test

parent 0c65a30c
import pymysql
import pandas as pd
from datetime import datetime
def con_sql(sql):
db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_test')
cursor = db.cursor()
cursor.execute(sql)
result = cursor.fetchall()
df = pd.DataFrame(list(result)).dropna()
db.close()
return df
if __name__ == "__main__":
now = datetime.now()
now_start = str(now)[:16] + ":00"
now_end = str(now)[:16] + ":59"
sql = "select device_id from user_active_time " \
"where active_time <= '{}' and active_time >= '{}'".format(now_end, now_start)
df = con_sql(sql)
print(df.head(1))
\ No newline at end of file
......@@ -14,7 +14,6 @@ def con_sql(sql):
cursor = db.cursor()
cursor.execute(sql)
result = cursor.fetchall()
print("成功从数据库获取数据")
df = pd.DataFrame(list(result)).dropna()
db.close()
return df
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment