结构优化
This commit is contained in:
@ -2,10 +2,10 @@ import csv
|
||||
|
||||
def update_user_profile(user_data, profile_wifi_ssid):
|
||||
"""
|
||||
Updates user profile information in the Users.csv file.
|
||||
Args:
|
||||
user_data (dict): A dictionary containing user profile data (e.g., 'User', 'User_pass', etc.).
|
||||
profile_wifi_ssid (str): The Wifi_SSID of the user to update.
|
||||
更新Users.csv文件中的用户配置文件信息。
|
||||
参数:
|
||||
user_data:一个包含用户配置文件数据的字典
|
||||
profile_wifi_ssid:要更新的用户的Wifi_SSID
|
||||
"""
|
||||
with open('data/Users.csv', "r", encoding="utf-8") as file:
|
||||
csv_reader = csv.DictReader(file, delimiter=",")
|
||||
@ -18,18 +18,12 @@ def update_user_profile(user_data, profile_wifi_ssid):
|
||||
row['Wifi_SSID'] = user_data['Wifi_SSID']
|
||||
row['Modbus_IP'] = user_data['Modbus_IP']
|
||||
row['Modbus_Port'] = user_data['Modbus_Port']
|
||||
# The original code had 'Reserve' overwritten twice. Assuming it's a single 'Reserve' column.
|
||||
# If there are two distinct 'Reserve' fields (e.g., branch and semester), the CSV header and logic need clarification.
|
||||
# For now, I'll use the last assigned value for 'Reserve' as per original logic.
|
||||
row['Reserve'] = user_data['Reserve_branch'] # Assuming this is for branch
|
||||
row['Reserve'] = user_data['Reserve_semester'] # This will overwrite the previous 'Reserve' value
|
||||
row['NFC_ID'] = user_data['NFC_ID']
|
||||
row['Reserve'] = user_data['Reserve']
|
||||
break
|
||||
|
||||
with open('data/Users.csv', newline="", mode="w", encoding="utf-8") as file:
|
||||
# The original header had two 'Reserve' columns. This is unusual for CSV and might be a typo.
|
||||
# I will use a single 'Reserve' column as it's more common, or clarify if two are truly needed.
|
||||
# Based on the original code, it seems like the second 'Reserve' assignment overwrites the first.
|
||||
header = ["User", "User_pass", "Wifi_SSID", "Modbus_IP", "Modbus_Port", "Reserve"]
|
||||
header = ["User", "User_pass", "Wifi_SSID", "Modbus_IP", "Modbus_Port", "NFC_ID", "Reserve"]
|
||||
csv_writer = csv.DictWriter(file, fieldnames=header)
|
||||
csv_writer.writeheader()
|
||||
csv_writer.writerows(rows)
|
||||
Reference in New Issue
Block a user