Spaces:
Paused
Paused
fix: FILE_RFP_EXCEL_COUNT and error messeges print problem fix
Browse files- bot_telegram.py +26 -20
bot_telegram.py
CHANGED
|
@@ -18,7 +18,7 @@ BOT_SECRET_PASSWORD = os.getenv("BOT_SECRET_PASSWORD")
|
|
| 18 |
BOT_TOKEN = os.getenv("BOT_TOKEN")
|
| 19 |
BASE_URL = os.getenv("BASE_URL")
|
| 20 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 21 |
-
|
| 22 |
# API_USERNAME = os.getenv("API_USERNAME")
|
| 23 |
# API_PASSWORD = os.getenv("API_PASSWORD")
|
| 24 |
|
|
@@ -231,35 +231,41 @@ class TelegramBot:
|
|
| 231 |
df = pd.read_excel(io.BytesIO(file_bytes), sheet_name='rfp')
|
| 232 |
# Add debug logging
|
| 233 |
logging.info(f"Excel columns found: {df.columns.tolist()}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
except Exception as e:
|
|
|
|
| 235 |
await update.message.reply_text(
|
| 236 |
f"β Error reading Excel file: {str(e)}\n"
|
| 237 |
f"Please make sure the file has 'rfp' sheet with 'question' column."
|
| 238 |
)
|
| 239 |
return
|
| 240 |
-
|
| 241 |
-
if df.empty:
|
| 242 |
-
await update.message.reply_text(
|
| 243 |
-
"β Error: Excel file is empty."
|
| 244 |
-
)
|
| 245 |
-
return
|
| 246 |
-
|
| 247 |
-
# Add debug logging before check
|
| 248 |
-
logging.info("Checking for 'question' column...")
|
| 249 |
-
if 'question' not in df.columns:
|
| 250 |
-
logging.info("'question' column not found!")
|
| 251 |
-
await update.message.reply_text(
|
| 252 |
-
"β Error: Excel file does not have 'question' column.\n"
|
| 253 |
-
"Please make sure your Excel file has a column named 'question'."
|
| 254 |
-
)
|
| 255 |
-
return
|
| 256 |
#print("debug 1")
|
| 257 |
#print("FILE_RFP_EXCEL_COUNT: ",FILE_RFP_EXCEL_COUNT)
|
| 258 |
#print("type: ",type(FILE_RFP_EXCEL_COUNT))
|
| 259 |
-
if df['question'].count() >
|
| 260 |
await update.message.reply_text(
|
| 261 |
-
|
| 262 |
-
f"
|
|
|
|
|
|
|
| 263 |
)
|
| 264 |
return
|
| 265 |
|
|
|
|
| 18 |
BOT_TOKEN = os.getenv("BOT_TOKEN")
|
| 19 |
BASE_URL = os.getenv("BASE_URL")
|
| 20 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 21 |
+
FILE_RFP_EXCEL_COUNT = int(os.getenv("FILE_RFP_EXCEL_COUNT", "100")) # Default to 100 if not set
|
| 22 |
# API_USERNAME = os.getenv("API_USERNAME")
|
| 23 |
# API_PASSWORD = os.getenv("API_PASSWORD")
|
| 24 |
|
|
|
|
| 231 |
df = pd.read_excel(io.BytesIO(file_bytes), sheet_name='rfp')
|
| 232 |
# Add debug logging
|
| 233 |
logging.info(f"Excel columns found: {df.columns.tolist()}")
|
| 234 |
+
|
| 235 |
+
# Check for empty dataframe first
|
| 236 |
+
if df.empty:
|
| 237 |
+
await update.message.reply_text(
|
| 238 |
+
"β Error: Excel file is empty."
|
| 239 |
+
)
|
| 240 |
+
return
|
| 241 |
+
|
| 242 |
+
# Check for question column and make it case-insensitive
|
| 243 |
+
columns_lower = [col.lower() for col in df.columns]
|
| 244 |
+
if 'question' not in columns_lower:
|
| 245 |
+
logging.info(f"'question' column not found in columns: {df.columns.tolist()}")
|
| 246 |
+
await update.message.reply_text(
|
| 247 |
+
"β Error: Excel file does not have 'question' column.\n"
|
| 248 |
+
"Please make sure your Excel file has a column named 'question'.\n"
|
| 249 |
+
f"Found columns: {', '.join(df.columns.tolist())}"
|
| 250 |
+
)
|
| 251 |
+
return
|
| 252 |
+
|
| 253 |
except Exception as e:
|
| 254 |
+
logging.error(f"Error reading Excel: {str(e)}")
|
| 255 |
await update.message.reply_text(
|
| 256 |
f"β Error reading Excel file: {str(e)}\n"
|
| 257 |
f"Please make sure the file has 'rfp' sheet with 'question' column."
|
| 258 |
)
|
| 259 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
#print("debug 1")
|
| 261 |
#print("FILE_RFP_EXCEL_COUNT: ",FILE_RFP_EXCEL_COUNT)
|
| 262 |
#print("type: ",type(FILE_RFP_EXCEL_COUNT))
|
| 263 |
+
if df['question'].count() > FILE_RFP_EXCEL_COUNT:
|
| 264 |
await update.message.reply_text(
|
| 265 |
+
"β Error: Too many questions in Excel file!\n"
|
| 266 |
+
f"Your file has {df['question'].count()} questions.\n"
|
| 267 |
+
f"Maximum allowed is {FILE_RFP_EXCEL_COUNT} questions.\n"
|
| 268 |
+
"Please reduce the number of questions and try again."
|
| 269 |
)
|
| 270 |
return
|
| 271 |
|