removed depreceated code, and logs

This commit is contained in:
2026-05-10 13:26:11 +01:00
parent 4726582379
commit ee746d0abe
5 changed files with 41 additions and 12 deletions

View File

@@ -95,7 +95,7 @@ POCKETBASE_ADMIN_PASSWORD=secret
Start the bot with the project's entrypoint (example):
```bash
python bot.py
python main.py
```
The bot listens for commands:

Binary file not shown.

View File

@@ -47,10 +47,9 @@ async def parse_page(content: str, entry_type: str = "opportunity"):
# 1. Run the agent (which returns a string)
print(f"Parsing {entry_type}...")
print(content)
# print(content)
result = await agent.run(content)
raw_text = result.output
print(raw_text)
# 2. Clean the string
# We remove the markdown decorators so json.loads doesn't crash

37
bot.py
View File

@@ -1,6 +1,7 @@
import os
import asyncio
import logging
from contextlib import suppress
from dotenv import load_dotenv
from functools import wraps
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
@@ -12,6 +13,7 @@ from database import upload_entry
from scraper import get_clean_content
load_dotenv()
logging.getLogger("httpx").setLevel(logging.WARNING)
# Configuration
TOKEN = os.getenv("TG_TOKEN")
@@ -260,20 +262,39 @@ async def button_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
else:
await query.edit_message_text("🗑️ Discarded.")
# --- Main Entry ---
if __name__ == '__main__':
# Main Entry Point
async def _main():
application = ApplicationBuilder().token(TOKEN).build()
# Add Handlers
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("op", handle_opportunity))
application.add_handler(CommandHandler("ev", handle_event))
application.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), handle_followup_text))
application.add_handler(CallbackQueryHandler(button_handler))
# Start the worker thread
loop = asyncio.get_event_loop()
loop.create_task(worker())
async with application:
await application.initialize()
await application.start()
print("🤖 Bot is running...")
application.run_polling()
worker_task = asyncio.create_task(worker())
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())

9
main.py Normal file
View File

@@ -0,0 +1,9 @@
"""Entrypoint to run the bot.
This simply runs `bot.py` as a script so you can start the bot with
`python main.py`.
"""
import runpy
if __name__ == '__main__':
runpy.run_path('bot.py', run_name='__main__')