fmab777 commited on
Commit
045ba8b
·
verified ·
1 Parent(s): c83a4a7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -7
main.py CHANGED
@@ -848,9 +848,11 @@ async def process_summary_task( user_id: int, chat_id: int, message_id_to_edit:
848
  logger.warning(f"[Task {task_id}] Failed edit original msg {original_msg_id}: {e}.")
849
  # Continue anyway, will just send result as new message later
850
 
851
- # Indicate activity
852
- try: await retry_bot_operation(bot.send_chat_action, chat_id=chat_id, action='typing')
853
- except Exception: pass
 
 
854
 
855
  # --- Get Content ---
856
  is_yt = is_youtube_url(url)
@@ -865,13 +867,21 @@ async def process_summary_task( user_id: int, chat_id: int, message_id_to_edit:
865
  content = await get_website_content_via_crawl4ai(url)
866
  if not content:
867
  logger.warning(f"[Task {task_id}] Crawl4AI failed. Trying BS4...")
868
- try: await retry_bot_operation(bot.send_chat_action, chat_id, action='typing'); except Exception: pass
 
 
 
 
869
  content = await get_website_content_bs4(url)
870
  if not content:
871
  logger.warning(f"[Task {task_id}] BS4 failed. Trying API...")
872
  global URLTOTEXT_API_KEY, _urltotext_fallback_enabled
873
  if _urltotext_fallback_enabled:
874
- try: await retry_bot_operation(bot.send_chat_action, chat_id, action='typing'); except Exception: pass
 
 
 
 
875
  content = await get_website_content_via_api(url, URLTOTEXT_API_KEY)
876
  if not content: feedback = "Fetch failed (Crawl4AI/BS4/API error or credits)."
877
  else:
@@ -883,7 +893,11 @@ async def process_summary_task( user_id: int, chat_id: int, message_id_to_edit:
883
  # --- Generate Summary ---
884
  if content and not feedback:
885
  logger.info(f"[Task {task_id}] Content fetched (len:{len(content)}). Generating summary...")
886
- try: await retry_bot_operation(bot.send_chat_action, chat_id, action='typing'); except Exception: pass
 
 
 
 
887
  final_summary = await generate_summary(content, summary_type)
888
 
889
  if final_summary.startswith("Error:") or final_summary.startswith("Sorry,"):
@@ -900,7 +914,7 @@ async def process_summary_task( user_id: int, chat_id: int, message_id_to_edit:
900
  current_part = line[:MAX_SUMMARY_CHUNK_SIZE] if len(line) > MAX_SUMMARY_CHUNK_SIZE else line
901
  else: current_part += line
902
  if current_part.strip(): summary_parts.append(current_part.strip())
903
- if not summary_parts: parts.append("Summary generated, but empty."); logger.warning(...)
904
 
905
  logger.info(f"[Task {task_id}] Summary OK (len: {len(final_summary)}). Sending {len(summary_parts)} part(s).")
906
  feedback = summary_parts[0] # First part becomes the feedback message
 
848
  logger.warning(f"[Task {task_id}] Failed edit original msg {original_msg_id}: {e}.")
849
  # Continue anyway, will just send result as new message later
850
 
851
+ # Indicate activity --- FIX APPLIED ---
852
+ try:
853
+ await retry_bot_operation(bot.send_chat_action, chat_id=chat_id, action='typing')
854
+ except Exception:
855
+ pass
856
 
857
  # --- Get Content ---
858
  is_yt = is_youtube_url(url)
 
867
  content = await get_website_content_via_crawl4ai(url)
868
  if not content:
869
  logger.warning(f"[Task {task_id}] Crawl4AI failed. Trying BS4...")
870
+ # --- FIX APPLIED ---
871
+ try:
872
+ await retry_bot_operation(bot.send_chat_action, chat_id, action='typing')
873
+ except Exception:
874
+ pass
875
  content = await get_website_content_bs4(url)
876
  if not content:
877
  logger.warning(f"[Task {task_id}] BS4 failed. Trying API...")
878
  global URLTOTEXT_API_KEY, _urltotext_fallback_enabled
879
  if _urltotext_fallback_enabled:
880
+ # --- FIX APPLIED ---
881
+ try:
882
+ await retry_bot_operation(bot.send_chat_action, chat_id, action='typing')
883
+ except Exception:
884
+ pass
885
  content = await get_website_content_via_api(url, URLTOTEXT_API_KEY)
886
  if not content: feedback = "Fetch failed (Crawl4AI/BS4/API error or credits)."
887
  else:
 
893
  # --- Generate Summary ---
894
  if content and not feedback:
895
  logger.info(f"[Task {task_id}] Content fetched (len:{len(content)}). Generating summary...")
896
+ # --- FIX APPLIED ---
897
+ try:
898
+ await retry_bot_operation(bot.send_chat_action, chat_id, action='typing')
899
+ except Exception:
900
+ pass
901
  final_summary = await generate_summary(content, summary_type)
902
 
903
  if final_summary.startswith("Error:") or final_summary.startswith("Sorry,"):
 
914
  current_part = line[:MAX_SUMMARY_CHUNK_SIZE] if len(line) > MAX_SUMMARY_CHUNK_SIZE else line
915
  else: current_part += line
916
  if current_part.strip(): summary_parts.append(current_part.strip())
917
+ if not summary_parts: summary_parts.append("Summary generated, but empty."); logger.warning(f"[Task {task_id}] Summary generated but resulted in empty parts.") # Added logging/fallback text
918
 
919
  logger.info(f"[Task {task_id}] Summary OK (len: {len(final_summary)}). Sending {len(summary_parts)} part(s).")
920
  feedback = summary_parts[0] # First part becomes the feedback message