From d66133725bc22ab6fe3f11ad8aa081716f6ef441 Mon Sep 17 00:00:00 2001 From: lsy2246 Date: Sat, 6 Apr 2024 19:52:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=8B=B1=E8=AF=AD=E5=AD=A6?= =?UTF-8?q?=E4=B9=A0=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/code/englishstudy.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/python/code/englishstudy.py b/python/code/englishstudy.py index d4776ab..a84c1ed 100644 --- a/python/code/englishstudy.py +++ b/python/code/englishstudy.py @@ -42,17 +42,23 @@ def detection_work_day(): cursor.execute('SELECT Date FROM Mistake WHERE Date = CURDATE();') rows = cursor.fetchall() - if len(rows) < 20: - cursor.execute('SELECT English,Chinese FROM Work') + if len(rows) < quantity: + cursor.execute('SELECT English,Chinese FROM Work where frequency = 0;') work = cursor.fetchall() - for _ in range(20 - len(rows)): + i = 0 + works = [] + while i < (quantity - len(rows)): test = random.choice(work) - English = test[0] - Chinese = test[1] - Data = time.strftime("%Y-%m-%d", time.localtime()) - cursor.execute('insert into Mistake(English, Chinese, Date)\n' - f"values ('{English}','{Chinese}','{Data}')") - conn.commit() + if test[0] not in works: + English = test[0] + Chinese = test[1] + works.append(English) + Data = time.strftime("%Y-%m-%d", time.localtime()) + 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() conn.close() @@ -63,7 +69,7 @@ def add_error(english): 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()