#!/usr/bin/env python3 """ Scheduler script for Flat Scraper Runs every 6 hours and sends notifications for new results """ import schedule import time import logging from src.main import FlatScraper # Configure logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) def run_scraper(): """Run the scraper once""" try: scraper = FlatScraper() scraper.run_once() except Exception as e: logging.error(f"Error running scraper: {e}") def main(): """Main scheduler function""" print('šŸ• Scheduler started. Running every 6 hours.') print('šŸ  Flat Scraper will check for new apartments automatically.') # Schedule every 6 hours schedule.every(6).hours.do(run_scraper) # Run immediately on start print('šŸš€ Running initial scrape...') run_scraper() # Keep running while True: try: schedule.run_pending() time.sleep(60) # Check every minute except KeyboardInterrupt: print('\nšŸ‘‹ Scheduler stopped by user.') break except Exception as e: logging.error(f"Scheduler error: {e}") time.sleep(300) # Wait 5 minutes on error if __name__ == "__main__": main()