lunarflu HF staff commited on
Commit
b270f3a
1 Parent(s): 5ffe4d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -69,7 +69,24 @@ async def search_csv(file_path, column_index, search_value):
69
  return None
70
 
71
 
 
 
 
 
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
 
75
 
@@ -108,10 +125,18 @@ async def add_exp(member_id):
108
  11: lvl11, 12: lvl12, 13: lvl13, 14: lvl14, 15: lvl15, 16: lvl16, 17: lvl17, 18: lvl18, 19: lvl19, 20: lvl20,
109
  }
110
  print(f"2")
111
- if member.id == 811235357663297546:
112
- # does a record already exist?
113
 
114
- await search_csv('data.csv', 0, member.id)
 
 
 
 
 
 
 
 
 
 
115
 
116
 
117
 
 
69
  return None
70
 
71
 
72
+ def is_csv_empty(file_path):
73
+ if not os.path.isfile(file_path):
74
+ print(f"The file '{file_path}' does not exist.")
75
+ return False
76
 
77
+ with open(file_path, 'r', newline='') as csvfile:
78
+ reader = csv.reader(csvfile)
79
+ try:
80
+ first_row = next(reader)
81
+ except StopIteration:
82
+ print(f"The file '{file_path}' is empty.")
83
+ return False
84
+
85
+ if not any(first_row):
86
+ print(f"The file '{file_path}' has no data.")
87
+ return False
88
+
89
+ return True
90
 
91
 
92
 
 
125
  11: lvl11, 12: lvl12, 13: lvl13, 14: lvl14, 15: lvl15, 16: lvl16, 17: lvl17, 18: lvl18, 19: lvl19, 20: lvl20,
126
  }
127
  print(f"2")
 
 
128
 
129
+
130
+
131
+ csv_file_path = 'data.csv'
132
+ if is_csv_empty(csv_file_path):
133
+ print(f"The CSV file '{csv_file_path}' exists and has data.")
134
+ else:
135
+ print(f"The CSV file '{csv_file_path}' does not exist or is empty.")
136
+
137
+
138
+
139
+ #await search_csv(csv_file_path, 0, member.id)
140
 
141
 
142