diff --git a/docker-compose.yml b/docker-compose.yml index a3d1e9f..8a0c93b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,7 +21,6 @@ services: - ./.env:/app/.env:ro environment: - TZ=Europe/Vienna - command: python scheduler.py - # platform: linux/arm64 + command: python src/scheduler.py depends_on: - flat-scraper diff --git a/src/scheduler.py b/src/scheduler.py new file mode 100755 index 0000000..fe4f02c --- /dev/null +++ b/src/scheduler.py @@ -0,0 +1,51 @@ +#!/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()