mirror of
https://gitlab.dit.htwk-leipzig.de/fsr-im/tools/flatscraper.git
synced 2025-08-30 01:53:52 +02:00
style: clean up whitespace and formatting in main.py and webhook.py
This commit is contained in:
13
main.py
13
main.py
@@ -1,4 +1,3 @@
|
|||||||
from bs4 import BeautifulSoup
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import src.wogetra.scraper as wogetra_scraper
|
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
|
# Store known property IDs to avoid duplicate notifications
|
||||||
known_properties = set()
|
known_properties = set()
|
||||||
|
|
||||||
|
|
||||||
# Main loop to periodically check for new listings
|
# Main loop to periodically check for new listings
|
||||||
def main():
|
def main():
|
||||||
global known_properties
|
global known_properties
|
||||||
@@ -28,11 +28,11 @@ def main():
|
|||||||
while True:
|
while True:
|
||||||
current_time = time.strftime("%H:%M:%S", time.localtime())
|
current_time = time.strftime("%H:%M:%S", time.localtime())
|
||||||
print("Scraping properties at " + current_time)
|
print("Scraping properties at " + current_time)
|
||||||
|
|
||||||
properties_wogetra = wogetra_scraper.scrape_wogetra()
|
properties_wogetra = wogetra_scraper.scrape_wogetra()
|
||||||
print("Scraped " + str(len(properties_wogetra)) + " properties from Wogetra")
|
print("Scraped " + str(len(properties_wogetra)) + " properties from Wogetra")
|
||||||
properties = properties_wogetra
|
properties = properties_wogetra
|
||||||
|
|
||||||
properties_lwb = lwb_scraper.scrape_easysquare()
|
properties_lwb = lwb_scraper.scrape_easysquare()
|
||||||
print("Scraped " + str(len(properties_lwb)) + " properties from LWB")
|
print("Scraped " + str(len(properties_lwb)) + " properties from LWB")
|
||||||
properties += properties_lwb
|
properties += properties_lwb
|
||||||
@@ -40,15 +40,14 @@ def main():
|
|||||||
properties_lipsia = lipsia_scraper.scrape_lipsia()
|
properties_lipsia = lipsia_scraper.scrape_lipsia()
|
||||||
print("Scraped " + str(len(properties_lipsia)) + " properties from Lipsia")
|
print("Scraped " + str(len(properties_lipsia)) + " properties from Lipsia")
|
||||||
properties += properties_lipsia
|
properties += properties_lipsia
|
||||||
|
|
||||||
properties_bgl = bgl_scraper.fetch_all_properties()
|
properties_bgl = bgl_scraper.fetch_all_properties()
|
||||||
print("Scraped " + str(len(properties_bgl)) + " properties from BGL")
|
print("Scraped " + str(len(properties_bgl)) + " properties from BGL")
|
||||||
properties += properties_bgl
|
properties += properties_bgl
|
||||||
|
|
||||||
properties_vlw = vlw_scraper.scrape_vlw()
|
properties_vlw = vlw_scraper.scrape_vlw()
|
||||||
print("Scraped " + str(len(properties_vlw)) + " properties from VLW")
|
print("Scraped " + str(len(properties_vlw)) + " properties from VLW")
|
||||||
properties = properties_vlw
|
properties += properties_vlw
|
||||||
|
|
||||||
|
|
||||||
for prop in properties:
|
for prop in properties:
|
||||||
if prop["id"] not in known_properties:
|
if prop["id"] not in known_properties:
|
||||||
@@ -56,7 +55,6 @@ def main():
|
|||||||
localwebhook.send_to_discord(prop)
|
localwebhook.send_to_discord(prop)
|
||||||
known_properties.add(prop["id"])
|
known_properties.add(prop["id"])
|
||||||
|
|
||||||
|
|
||||||
# save known properties to file
|
# save known properties to file
|
||||||
with open("known_properties.json", "w") as file:
|
with open("known_properties.json", "w") as file:
|
||||||
json.dump(list(known_properties), file)
|
json.dump(list(known_properties), file)
|
||||||
@@ -65,5 +63,6 @@ def main():
|
|||||||
print("Waiting for the next check...")
|
print("Waiting for the next check...")
|
||||||
time.sleep(300) # Check every 5 minutes
|
time.sleep(300) # Check every 5 minutes
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@@ -8,6 +8,7 @@ load_dotenv()
|
|||||||
# Webhook URL from Discord
|
# Webhook URL from Discord
|
||||||
WEBHOOK_URL = os.getenv("WEBHOOK_URL")
|
WEBHOOK_URL = os.getenv("WEBHOOK_URL")
|
||||||
|
|
||||||
|
|
||||||
# Funktion: Nachricht an Discord senden
|
# Funktion: Nachricht an Discord senden
|
||||||
def send_to_discord(property_data):
|
def send_to_discord(property_data):
|
||||||
|
|
||||||
@@ -23,10 +24,9 @@ def send_to_discord(property_data):
|
|||||||
f"**Beschreibung:** {property_data['abstract']}"
|
f"**Beschreibung:** {property_data['abstract']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Set headers
|
# Set headers
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
|
|
||||||
# Check for optional image URL
|
# Check for optional image URL
|
||||||
if "image_url" in property_data and property_data["image_url"]:
|
if "image_url" in property_data and property_data["image_url"]:
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user