fix emojis

This commit is contained in:
Aron Petau 2026-01-02 11:23:35 +01:00
parent c45c6992ae
commit 287b1b154f
5 changed files with 39 additions and 32 deletions

23
main.py
View file

@ -1,4 +1,3 @@
import asyncio
from playwright.async_api import async_playwright
from application_handler import ApplicationHandler
@ -22,13 +21,13 @@ logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)-5s] %(name)-20s | %(message)s",
handlers=[
RotatingFileHandler("data/monitor.log", maxBytes=1 * 1024 * 1024, backupCount=3), # 1 MB per file, 3 backups
RotatingFileHandler("data/monitor.log", maxBytes=1 * 1024 * 1024, backupCount=3),
logging.StreamHandler()
],
force=True # Enforce for all modules, Python 3.8+
)
logger = logging.getLogger(__name__) # Use named logger
logger.info("🚀 Bot starting | Logs: data/monitor.log + console")
logger.info("Bot starting | Logs: data/monitor.log + console")
# Interval (seconds) between checks for new listings
CHECK_INTERVAL = int(os.getenv("CHECK_INTERVAL", 300)) # Default: 300 seconds
@ -96,7 +95,7 @@ async def init_browser_context() -> tuple:
return playwright, browser, browser_context
async def main() -> None:
logger.info("🤖 Initializing wohn-bot...")
logger.info("Initializing wohn-bot...")
# Validate configuration before starting
if not validate_config():
@ -106,7 +105,7 @@ async def main() -> None:
state_manager = StateManager(Path("data/state.json"))
# --- Playwright browser/context setup with recovery ---
logger.info("🌐 Initializing browser...")
logger.info("Initializing browser...")
playwright, browser, browser_context = await init_browser_context()
# Application handler manages browser/context
@ -134,16 +133,16 @@ async def main() -> None:
try:
deleted = autoclean_debug_material()
if deleted:
logger.info(f"🧹 Cleaned {len(deleted)} debug files (48h)")
logger.info(f"Cleaned {len(deleted)} debug files (48h)")
except Exception as e:
logger.warning(f"⚠️ Autoclean failed: {e}")
logger.warning(f"Autoclean failed: {e}")
last_clean = now
try:
current_listings = await app_handler.fetch_listings()
except Exception as e:
logger.error(f"💥 Browser crash: {e}")
logger.info("🔄 Recovering...")
logger.info("Recovering...")
try:
await browser.close()
await playwright.stop()
@ -154,7 +153,7 @@ async def main() -> None:
try:
playwright, browser, browser_context = await init_browser_context()
app_handler.context = browser_context
logger.info("Browser recovered")
logger.info("Browser recovered")
await asyncio.sleep(5)
continue
except Exception as recovery_error:
@ -163,7 +162,7 @@ async def main() -> None:
continue
if not current_listings:
logger.warning("⚠️ No listings fetched")
logger.warning("No listings fetched")
await asyncio.sleep(CHECK_INTERVAL)
_flush_rotating_file_handlers()
continue
@ -192,10 +191,10 @@ async def main() -> None:
new_listings = app_handler.find_new_listings(current_listings, previous_listings)
application_results = {}
if new_listings:
logger.info(f"\ud83c\udfe0 {len(new_listings)} new listing{'s' if len(new_listings) > 1 else ''} detected")
logger.info(f"{len(new_listings)} new listing{'s' if len(new_listings) > 1 else ''} detected")
app_handler.log_listing_times(new_listings)
if app_handler.is_autopilot_enabled():
logger.info("\ud83e\udd16 Autopilot active - applying...")
logger.info("Autopilot active - applying...")
application_results = await app_handler.apply_to_listings(new_listings)
app_handler.notify_new_listings(new_listings, application_results)
app_handler.save_listings(current_listings)