mirror of
https://gitlab.dit.htwk-leipzig.de/fsr-im/tools/flatscraper.git
synced 2026-01-17 22:12:26 +01:00
add scraping functionality for Lipsia and improve error handling for image downloads
This commit is contained in:
Binary file not shown.
@@ -33,6 +33,13 @@ def send_to_discord(property_data):
|
||||
# Download the image
|
||||
image_response = scrape_image.scrape_image(property_data["image_url"])
|
||||
|
||||
# Check if the image was downloaded successfully
|
||||
if image_response == b"":
|
||||
print("Fehler beim Herunterladen des Bildes: Leere Antwort")
|
||||
payload = {"content": message}
|
||||
response = requests.post(WEBHOOK_URL, data=json.dumps(payload), headers=headers)
|
||||
return
|
||||
|
||||
# Send the message with an image attachment
|
||||
files = {"file": ("image.jpg", image_response)}
|
||||
payload = {"content": message}
|
||||
|
||||
BIN
src/lipsia/__pycache__/lipsia.cpython-310.pyc
Normal file
BIN
src/lipsia/__pycache__/lipsia.cpython-310.pyc
Normal file
Binary file not shown.
38
src/lipsia/lipsia.py
Normal file
38
src/lipsia/lipsia.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import requests
|
||||
from datetime import datetime
|
||||
|
||||
def scrape_lipsia():
|
||||
url = "https://wg-lipsia.de/wp-admin/admin-ajax.php?action=emk_immosearch_api&endpoint=list"
|
||||
response = requests.get(url)
|
||||
|
||||
if response.status_code != 200:
|
||||
print(f"Failed to fetch data: {response.status_code}")
|
||||
return []
|
||||
|
||||
data = response.json()
|
||||
if data["status"] != "success":
|
||||
print("Failed to fetch properties: Invalid response status")
|
||||
return []
|
||||
|
||||
properties = []
|
||||
for item in data["list"]:
|
||||
|
||||
lat = item.get("lat", "")
|
||||
lon = item.get("lon", "")
|
||||
google_maps_link = f"https://www.google.com/maps/search/?api=1&query={lat},{lon}"
|
||||
|
||||
properties.append({
|
||||
"id": item.get("id"),
|
||||
"title": "Lipsia - " + item.get("headline", ""),
|
||||
"subtitle": item.get("adresse_strasse", "") + " " + item.get("adresse_plz_ort", ""),
|
||||
"rooms": item.get("zimmer_anzahl", 0),
|
||||
"size": str(item.get("wohnflaeche", 0)) + " m²",
|
||||
"rent": "Kalt: " + str(item.get("miete_kalt_euro", 0)) + " €",
|
||||
"link": google_maps_link,
|
||||
"abstract": item.get("highlight_1", ""),
|
||||
"warm_rent": "", # Placeholder as warm rent is not provided
|
||||
"availability": (item.get("highlight_3", "")), # Customize as needed
|
||||
"image_url": item.get("image", ""),
|
||||
})
|
||||
|
||||
return properties
|
||||
Binary file not shown.
Binary file not shown.
@@ -27,7 +27,8 @@ def scrape_image(url):
|
||||
|
||||
if response.status_code != 200:
|
||||
print(f"Fehler beim Abrufen von Easysquare: {response.status_code}")
|
||||
return []
|
||||
# return empty image
|
||||
return b''
|
||||
|
||||
# get image from response
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ def scrape_easysquare():
|
||||
|
||||
properties.append({
|
||||
"id": id,
|
||||
"title": prop_title,
|
||||
"title": "LWB - " + prop_title,
|
||||
"subtitle": subtitle,
|
||||
"rooms": format.format_room(rooms),
|
||||
"size": format.format_roomSize(size),
|
||||
|
||||
Binary file not shown.
@@ -35,7 +35,7 @@ def scrape_wogetra():
|
||||
# Add property to list
|
||||
properties.append({
|
||||
"id": property_id,
|
||||
"title": title,
|
||||
"title": "Wogetra - "+ title,
|
||||
"subtitle": subtitle,
|
||||
"rooms": rooms,
|
||||
"size": size,
|
||||
|
||||
Reference in New Issue
Block a user