move scheduler.py to src

This commit is contained in:
flo-eberle
2026-02-15 12:32:07 +01:00
parent 82efdbf4be
commit f6c7d6690e
2 changed files with 52 additions and 2 deletions

View File

@@ -21,7 +21,6 @@ services:
- ./.env:/app/.env:ro - ./.env:/app/.env:ro
environment: environment:
- TZ=Europe/Vienna - TZ=Europe/Vienna
command: python scheduler.py command: python src/scheduler.py
# platform: linux/arm64
depends_on: depends_on:
- flat-scraper - flat-scraper

51
src/scheduler.py Executable file
View File

@@ -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()