GetQzonehistory/util/ConfigUtil.py

65 lines
1.7 KiB
Python
Raw Normal View History

2024-02-13 05:45:57 +00:00
import configparser
2024-02-13 06:17:34 +00:00
import os
2024-02-13 05:45:57 +00:00
config = configparser.ConfigParser()
config.read('./resource/config/config.ini')
temp_path = config.get('File', 'temp')
2024-02-13 06:17:34 +00:00
user_path = config.get('File', 'user')
result_path = config.get('File', 'result')
2024-02-13 06:17:34 +00:00
def save_user(cookies):
with open(user_path + cookies.get('uin'), 'w') as f:
f.write(str(cookies))
2024-02-14 01:07:53 +00:00
def init_flooder():
# 初始化temp文件夹
if not os.path.exists(temp_path):
os.makedirs(temp_path)
print(f"Created directory: {temp_path}")
# 初始化user文件夹
if not os.path.exists(user_path):
os.makedirs(user_path)
print(f"Created directory: {user_path}")
# 初始化result文件夹
if not os.path.exists(result_path):
os.makedirs(result_path)
print(f"Created directory: {result_path}")
2024-02-13 06:17:34 +00:00
def read_files_in_folder():
# 获取文件夹下的所有文件
files = os.listdir(user_path)
2024-02-13 06:24:46 +00:00
# 如果文件夹为空
if not files:
return None
2024-02-13 06:17:34 +00:00
# 输出文件列表
2024-02-13 06:24:46 +00:00
print("已登录用户列表:")
2024-02-13 06:17:34 +00:00
for i, file in enumerate(files):
print(f"{i + 1}. {file}")
# 选择文件
2024-02-13 06:24:46 +00:00
while True:
try:
2024-02-14 01:12:18 +00:00
choice = int(input("请选择要登录的用户序号重新登录输入0: "))
2024-02-13 06:24:46 +00:00
if 1 <= choice <= len(files):
break
elif choice == 0:
return None
2024-02-13 06:24:46 +00:00
else:
print("无效的选择,请重新输入。")
except ValueError:
print("无效的选择,请重新输入。")
2024-02-13 06:17:34 +00:00
# 读取选择的文件
selected_file = files[choice - 1]
file_path = os.path.join(user_path, selected_file)
with open(file_path, 'r') as file:
content = file.read()
return content