You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
# -*- coding: gbk -*-
|
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
|
import mysql
|
|
|
|
|
import mysql.connector
|
|
|
|
|
import csv
|
|
|
|
|
|
|
|
|
|
db_config = {
|
|
|
|
|
'host': 'localhost',
|
|
|
|
|
'user': 'root',
|
|
|
|
|
'password': '21412030115',
|
|
|
|
|
'database': '<EFBFBD><EFBFBD>ɳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cnx = mysql.connector.connect(**db_config)
|
|
|
|
|
cursor = cnx.cursor()
|
|
|
|
|
|
|
|
|
|
# <20><>ȡCSV
|
|
|
|
|
with open('changsha<EFBFBD><EFBFBD><EFBFBD><EFBFBD>.csv', mode='r', encoding='gbk') as file:
|
|
|
|
|
reader = csv.reader(file)
|
|
|
|
|
headers = next(reader, None)
|
|
|
|
|
if headers is not None: # <20><><EFBFBD><EFBFBD>ͷ
|
|
|
|
|
for row in reader:
|
|
|
|
|
sql = "INSERT IGNORE INTO <20><>ɳ<EFBFBD><C9B3><EFBFBD><EFBFBD>(date, high_temperature, low_temperature, weather,fengsu) VALUES (%s, %s, %s, %s,%s)"
|
|
|
|
|
cursor.execute(sql, (row[0], row[1], row[2], row[3], row[4])) #<23><>csv<73><76><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>Ӧ
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
cnx.commit()
|
|
|
|
|
print("<EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>")
|
|
|
|
|
except mysql.connector.Error as err:
|
|
|
|
|
print(f"<EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>: {err}")
|
|
|
|
|
finally:
|
|
|
|
|
cursor.close()
|
|
|
|
|
cnx.close()
|