更新英语学习工具

This commit is contained in:
lsy2246 2024-04-06 19:52:02 +08:00
parent 17506e7b90
commit d66133725b

View File

@ -42,17 +42,23 @@ def detection_work_day():
cursor.execute('SELECT Date FROM Mistake WHERE Date = CURDATE();') cursor.execute('SELECT Date FROM Mistake WHERE Date = CURDATE();')
rows = cursor.fetchall() rows = cursor.fetchall()
if len(rows) < 20: if len(rows) < quantity:
cursor.execute('SELECT English,Chinese FROM Work') cursor.execute('SELECT English,Chinese FROM Work where frequency = 0;')
work = cursor.fetchall() work = cursor.fetchall()
for _ in range(20 - len(rows)): i = 0
works = []
while i < (quantity - len(rows)):
test = random.choice(work) test = random.choice(work)
English = test[0] if test[0] not in works:
Chinese = test[1] English = test[0]
Data = time.strftime("%Y-%m-%d", time.localtime()) Chinese = test[1]
cursor.execute('insert into Mistake(English, Chinese, Date)\n' works.append(English)
f"values ('{English}','{Chinese}','{Data}')") Data = time.strftime("%Y-%m-%d", time.localtime())
conn.commit() cursor.execute('insert into Mistake(English, Chinese, Date)\n'
f"values ('{English}','{Chinese}','{Data}')")
cursor.execute(f"update Work set frequency = frequency+1 where English='{English}'")
conn.commit()
i += 1
cursor.close() cursor.close()
conn.close() conn.close()
@ -63,7 +69,7 @@ def add_error(english):
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(f"update Work set frequency = frequency+1 where English='{english}'") cursor.execute(f"update Work set erred = erred+1 where English='{english}'")
conn.commit() conn.commit()