init: QQ Bot - PS2 游戏数据查询机器人
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
|
||||
import csv
|
||||
|
||||
def read_csv_to_list(csv_file):
|
||||
"""
|
||||
将CSV文件读取为列表
|
||||
|
||||
参数:
|
||||
csv_file (str): CSV文件路径
|
||||
|
||||
返回:
|
||||
list: 包含所有行数据的列表,每行是一个子列表
|
||||
"""
|
||||
data_list = []
|
||||
|
||||
try:
|
||||
with open(csv_file, 'r', encoding='utf-8') as file:
|
||||
# 创建CSV阅读器
|
||||
csv_reader = csv.reader(file)
|
||||
|
||||
# 跳过标题行(可选)
|
||||
next(csv_reader) # 去掉这行如果不需要跳过标题
|
||||
|
||||
# 逐行读取
|
||||
for row in csv_reader:
|
||||
data_list.append(row)
|
||||
|
||||
return data_list
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"错误: 文件 {csv_file} 不存在")
|
||||
return []
|
||||
except Exception as e:
|
||||
print(f"读取CSV时出错: {str(e)}")
|
||||
return []
|
||||
|
||||
def find_id(id,data_list):
|
||||
|
||||
for sublist in data_list:
|
||||
if id in sublist:
|
||||
found = True
|
||||
break # 找到第一个匹配项就停止
|
||||
|
||||
return sublist
|
||||
start = read_csv_to_list(r'C:\Cq-http\NoneBot\Git_Plugins\QQbot\csv\nickname.csv')
|
||||
st1 = find_id('4',start)
|
||||
print(st1)
|
||||
Reference in New Issue
Block a user