Skip to content

Commit

Permalink
fix: add the situtation when table.txt not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaoborui committed Apr 15, 2024
1 parent bcc3828 commit f7975e2
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,19 @@ def writeToTable(username):
Returns:
None
"""
with open('table.txt', 'r') as f:
lines = f.readlines()
if len(lines) == 0:
with open('table.txt', 'a') as f:
f.write(str(datetime.now().date()) + '\n')
else:
if lines[0].strip() != str(datetime.now().date()):
with open('table.txt', 'w') as f:
if not os.path.exists('table.txt'):
with open('table.txt', 'w') as f:
f.write(str(datetime.now().date()) + '\n')
else:
with open('table.txt', 'r') as f:
lines = f.readlines()
if len(lines) == 0:
with open('table.txt', 'a') as f:
f.write(str(datetime.now().date()) + '\n')
else:
if lines[0].strip() != str(datetime.now().date()):
with open('table.txt', 'w') as f:
f.write(str(datetime.now().date()) + '\n')

#写入用户名
with open('table.txt', 'a') as f:
Expand All @@ -213,6 +217,8 @@ def readTable():
Returns:
list: The list of users who have signed in successfully.
"""
if not os.path.exists('table.txt'):
return []
with open('table.txt', 'r') as f:
lines = f.readlines()
return [line.strip() for line in lines[1:]]
Expand Down

0 comments on commit f7975e2

Please sign in to comment.