import json
import pymysql
import csv
conn = pymysql.connect(
host = '127.0.0.1',
port = 3306,
user = 'root',
passwd = 'admin',
db = 'tencent_demo',
charset = 'utf8',
)
cursor = conn.cursor()
with open("test3.csv","a",newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=' ')
writer.writerow(["原始数据","feature1","feature2"])
name = "qwe"
date = "2021-07-18"
sql = "select series,sample_id from sample_series where name = ? and date = ? "
try:
cursor.execute(sql,name,date)
results = cursor.fetchall()
series = results[0][0]
sample_id = results[0][1]
print(series,sample_id)
except:
print("Error: unable to fecth data")
sql = "select type from sample where id = ?"
try:
cursor.execute(sql,sample_id)
results = cursor.fetchall()
type = results[0][0]
print(type)
except:
print("Error: unable to fecth data")
sql = "select good,miss,doubt from mark where name = ? and sample_id = ?"
try:
cursor.execute(sql, name,sample_id)
results = cursor.fetchall()
good = results[0][0]
miss = results[0][1]
doubt = results[0][2]
print(good,miss,doubt)
except:
print("Error: unable to fecth data")
cursor.close()
conn.close()
|