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.
23 lines
869 B
23 lines
869 B
import os
|
|
from datetime import datetime
|
|
|
|
class HistoryManager:
|
|
def load_history(self, folder):
|
|
history = set()
|
|
if not os.path.exists(folder):
|
|
os.makedirs(folder)
|
|
return history
|
|
for file in os.listdir(folder):
|
|
if file.endswith(".txt"):
|
|
with open(os.path.join(folder, file), "r", encoding="utf-8") as f:
|
|
history.update(line.strip() for line in f if line.strip())
|
|
return history
|
|
|
|
def save_questions(self, folder, questions):
|
|
filename = datetime.now().strftime("%Y-%m-%d-%H-%M-%S.txt")
|
|
filepath = os.path.join(folder, filename)
|
|
with open(filepath, "w", encoding="utf-8") as f:
|
|
for i, q in enumerate(questions, 1):
|
|
f.write(f"{i}. {q}\n\n")
|
|
print(f"题目已保存到 {filepath}")
|