Spaces:
Paused
Paused
feat: added _process_excel_sync method
Browse files- bot_telegram.py +38 -0
bot_telegram.py
CHANGED
|
@@ -339,5 +339,43 @@ class TelegramBot:
|
|
| 339 |
await self.app.stop()
|
| 340 |
await self.app.shutdown()
|
| 341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
def init_bot():
|
| 343 |
return TelegramBot(bot_token=BOT_TOKEN,base_url=BASE_URL)
|
|
|
|
| 339 |
await self.app.stop()
|
| 340 |
await self.app.shutdown()
|
| 341 |
|
| 342 |
+
def _process_excel_sync(self, file_bytes, filename):
|
| 343 |
+
"""Synchronous function to process Excel file"""
|
| 344 |
+
try:
|
| 345 |
+
headers = {
|
| 346 |
+
"Authorization": f"Bearer {HF_TOKEN}",
|
| 347 |
+
"accept": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
# Create files payload
|
| 351 |
+
files = {
|
| 352 |
+
'file': (
|
| 353 |
+
filename,
|
| 354 |
+
file_bytes,
|
| 355 |
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
| 356 |
+
)
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
# Make the request
|
| 360 |
+
response = requests.post(
|
| 361 |
+
self.excel_url,
|
| 362 |
+
headers=headers,
|
| 363 |
+
files=files,
|
| 364 |
+
timeout=60 # 60 second timeout for Excel processing
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
if response.status_code == 200:
|
| 368 |
+
return response.content
|
| 369 |
+
else:
|
| 370 |
+
logging.error(f"Excel API Error: {response.status_code} - {response.text}")
|
| 371 |
+
return None
|
| 372 |
+
|
| 373 |
+
except requests.exceptions.Timeout:
|
| 374 |
+
logging.error("Excel processing timeout")
|
| 375 |
+
return None
|
| 376 |
+
except Exception as e:
|
| 377 |
+
logging.error(f"Excel processing error: {e}")
|
| 378 |
+
return None
|
| 379 |
+
|
| 380 |
def init_bot():
|
| 381 |
return TelegramBot(bot_token=BOT_TOKEN,base_url=BASE_URL)
|