diff --git a/main.py b/main.py index 3713ca4..319f9a5 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -from bs4 import BeautifulSoup import json import time import src.wogetra.scraper as wogetra_scraper @@ -14,6 +13,7 @@ TARGET_URL = "https://www.wogetra.de/immobilien-vermarktungsart/miete/" # Store known property IDs to avoid duplicate notifications known_properties = set() + # Main loop to periodically check for new listings def main(): global known_properties @@ -28,11 +28,11 @@ def main(): while True: current_time = time.strftime("%H:%M:%S", time.localtime()) print("Scraping properties at " + current_time) - + properties_wogetra = wogetra_scraper.scrape_wogetra() print("Scraped " + str(len(properties_wogetra)) + " properties from Wogetra") properties = properties_wogetra - + properties_lwb = lwb_scraper.scrape_easysquare() print("Scraped " + str(len(properties_lwb)) + " properties from LWB") properties += properties_lwb @@ -40,15 +40,14 @@ def main(): properties_lipsia = lipsia_scraper.scrape_lipsia() print("Scraped " + str(len(properties_lipsia)) + " properties from Lipsia") properties += properties_lipsia - + properties_bgl = bgl_scraper.fetch_all_properties() print("Scraped " + str(len(properties_bgl)) + " properties from BGL") properties += properties_bgl properties_vlw = vlw_scraper.scrape_vlw() print("Scraped " + str(len(properties_vlw)) + " properties from VLW") - properties = properties_vlw - + properties += properties_vlw for prop in properties: if prop["id"] not in known_properties: @@ -56,7 +55,6 @@ def main(): localwebhook.send_to_discord(prop) known_properties.add(prop["id"]) - # save known properties to file with open("known_properties.json", "w") as file: json.dump(list(known_properties), file) @@ -65,5 +63,6 @@ def main(): print("Waiting for the next check...") time.sleep(300) # Check every 5 minutes + if __name__ == "__main__": main() diff --git a/src/discord/webhook.py b/src/discord/webhook.py index b8412c9..5ae7fc8 100644 --- a/src/discord/webhook.py +++ b/src/discord/webhook.py @@ -8,6 +8,7 @@ load_dotenv() # Webhook URL from Discord WEBHOOK_URL = os.getenv("WEBHOOK_URL") + # Funktion: Nachricht an Discord senden def send_to_discord(property_data): @@ -23,10 +24,9 @@ def send_to_discord(property_data): f"**Beschreibung:** {property_data['abstract']}" ) - # Set headers headers = {"Content-Type": "application/json"} - + # Check for optional image URL if "image_url" in property_data and property_data["image_url"]: try: