removed depreceated code, and logs
This commit is contained in:
@@ -95,7 +95,7 @@ POCKETBASE_ADMIN_PASSWORD=secret
|
|||||||
Start the bot with the project's entrypoint (example):
|
Start the bot with the project's entrypoint (example):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python bot.py
|
python main.py
|
||||||
```
|
```
|
||||||
|
|
||||||
The bot listens for commands:
|
The bot listens for commands:
|
||||||
|
|||||||
Binary file not shown.
3
agent.py
3
agent.py
@@ -47,10 +47,9 @@ async def parse_page(content: str, entry_type: str = "opportunity"):
|
|||||||
|
|
||||||
# 1. Run the agent (which returns a string)
|
# 1. Run the agent (which returns a string)
|
||||||
print(f"Parsing {entry_type}...")
|
print(f"Parsing {entry_type}...")
|
||||||
print(content)
|
# print(content)
|
||||||
result = await agent.run(content)
|
result = await agent.run(content)
|
||||||
raw_text = result.output
|
raw_text = result.output
|
||||||
print(raw_text)
|
|
||||||
|
|
||||||
# 2. Clean the string
|
# 2. Clean the string
|
||||||
# We remove the markdown decorators so json.loads doesn't crash
|
# We remove the markdown decorators so json.loads doesn't crash
|
||||||
|
|||||||
39
bot.py
39
bot.py
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from contextlib import suppress
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
@@ -12,6 +13,7 @@ from database import upload_entry
|
|||||||
from scraper import get_clean_content
|
from scraper import get_clean_content
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
TOKEN = os.getenv("TG_TOKEN")
|
TOKEN = os.getenv("TG_TOKEN")
|
||||||
@@ -260,20 +262,39 @@ async def button_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
else:
|
else:
|
||||||
await query.edit_message_text("🗑️ Discarded.")
|
await query.edit_message_text("🗑️ Discarded.")
|
||||||
|
|
||||||
# --- Main Entry ---
|
# Main Entry Point
|
||||||
if __name__ == '__main__':
|
async def _main():
|
||||||
application = ApplicationBuilder().token(TOKEN).build()
|
application = ApplicationBuilder().token(TOKEN).build()
|
||||||
|
|
||||||
# Add Handlers
|
|
||||||
application.add_handler(CommandHandler("start", start))
|
application.add_handler(CommandHandler("start", start))
|
||||||
application.add_handler(CommandHandler("op", handle_opportunity))
|
application.add_handler(CommandHandler("op", handle_opportunity))
|
||||||
application.add_handler(CommandHandler("ev", handle_event))
|
application.add_handler(CommandHandler("ev", handle_event))
|
||||||
application.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), handle_followup_text))
|
application.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), handle_followup_text))
|
||||||
application.add_handler(CallbackQueryHandler(button_handler))
|
application.add_handler(CallbackQueryHandler(button_handler))
|
||||||
|
|
||||||
# Start the worker thread
|
async with application:
|
||||||
loop = asyncio.get_event_loop()
|
await application.initialize()
|
||||||
loop.create_task(worker())
|
await application.start()
|
||||||
|
|
||||||
print("🤖 Bot is running...")
|
worker_task = asyncio.create_task(worker())
|
||||||
application.run_polling()
|
print("🤖 Bot is running...")
|
||||||
|
|
||||||
|
await application.updater.start_polling()
|
||||||
|
|
||||||
|
# Keep running until interrupted
|
||||||
|
await asyncio.Event().wait()
|
||||||
|
|
||||||
|
# Graceful shutdown
|
||||||
|
await application.updater.stop()
|
||||||
|
worker_task.cancel()
|
||||||
|
with suppress(asyncio.CancelledError):
|
||||||
|
await worker_task
|
||||||
|
|
||||||
|
await application.stop()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||||
|
asyncio.run(_main())
|
||||||
Reference in New Issue
Block a user