- /actions/apply now no-ops (returns fresh partial) when a running application exists for this user+flat, or when a previous one succeeded. The list button was already visually disabled; this closes the direct-POST and double-click loopholes - Drop the one-line error message under flat entries in the list (bewerbung_detail still shows the full message + the forensic ZIP report) - Strip "min morgens" commute chip from the list; alert._flat_payload sends an empty connectivity dict so Maps.calculate_score is no longer called on every flat. Maps.calculate_score + Flat.connectivity stay in the codebase for easy re-enable (one-line swap in _flat_payload) - List entry shows "vor 23 min" instead of "entdeckt vor 23 min" - Bitwarden: rename profile email/immomio fields to opaque names (contact_addr, immomio_login, immomio_secret) + add data-bwignore across every settings form / input. Server-side update_profile maps the new field names back to the existing DB columns Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
107 lines
3.5 KiB
Python
107 lines
3.5 KiB
Python
import logging
|
|
import time
|
|
from rich.console import Console
|
|
from rich.logging import RichHandler
|
|
|
|
from flat import Flat
|
|
from scraper import Scraper
|
|
from settings import TIME_INTERVALL
|
|
from utils import hash_any_object
|
|
from web_client import WebClient
|
|
|
|
|
|
def setup_logging():
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(message)s",
|
|
datefmt="[%X]",
|
|
handlers=[RichHandler(markup=True, console=Console(width=110))],
|
|
)
|
|
logging.getLogger("googlemaps").setLevel(logging.WARNING)
|
|
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
|
|
|
|
|
logger = logging.getLogger("alert")
|
|
setup_logging()
|
|
|
|
|
|
class FlatAlerter:
|
|
def __init__(self):
|
|
self.web = WebClient()
|
|
self.last_response_hash = ""
|
|
|
|
def _flat_payload(self, flat: Flat) -> dict:
|
|
# Transit-connectivity is disabled to save Google-Maps quota. The
|
|
# helper on Flat (flat.connectivity → Maps.calculate_score) is
|
|
# intentionally kept so it can be re-enabled without re-writing code —
|
|
# just replace the empty dict with `flat.connectivity` when needed.
|
|
c: dict = {}
|
|
lat, lng = flat.coords
|
|
return {
|
|
"id": flat.id,
|
|
"link": flat.link,
|
|
"address": flat.address,
|
|
"rooms": flat.rooms,
|
|
"size": flat.size,
|
|
"cold_rent": flat.cold_rent,
|
|
"utilities": flat.utilities,
|
|
"total_rent": flat.total_rent,
|
|
"sqm_price": flat.sqm_price,
|
|
"available_from": flat.available_from,
|
|
"published_on": flat.published_on,
|
|
"wbs": flat.wbs,
|
|
"floor": flat.floor,
|
|
"bathrooms": flat.bathrooms,
|
|
"year_built": flat.year_built,
|
|
"heating": flat.heating,
|
|
"energy_carrier": flat.energy_carrier,
|
|
"energy_value": flat.energy_value,
|
|
"energy_certificate": flat.energy_certificate,
|
|
"address_link_gmaps": flat.address_link_gmaps,
|
|
"lat": lat,
|
|
"lng": lng,
|
|
"connectivity": {
|
|
"morning_time": c.get("morning_time", 0),
|
|
"morning_transfers": c.get("morning_transfers", 0),
|
|
"night_time": c.get("night_time", 0),
|
|
"night_transfers": c.get("night_transfers", 0),
|
|
},
|
|
"raw_data": flat.raw_data,
|
|
}
|
|
|
|
def scan(self):
|
|
logger.info("starting scan")
|
|
scraper = Scraper()
|
|
if not scraper.login():
|
|
return
|
|
flats_data = scraper.get_flats()
|
|
|
|
response_hashed = hash_any_object(flats_data)
|
|
if response_hashed == self.last_response_hash:
|
|
logger.info("no change since last scan")
|
|
return
|
|
self.last_response_hash = response_hashed
|
|
|
|
for number, data in enumerate(flats_data, 1):
|
|
flat = Flat(data)
|
|
logger.info(f"{str(number).rjust(2)}: submitting {flat}")
|
|
payload = self._flat_payload(flat)
|
|
if not self.web.submit_flat(payload):
|
|
logger.warning(f"\tcould not submit {flat.id} to web, will retry next loop")
|
|
logger.info("scan finished")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logger.info("starting lazyflat alert service")
|
|
alerter = FlatAlerter()
|
|
while True:
|
|
try:
|
|
alerter.scan()
|
|
alerter.web.heartbeat()
|
|
logger.info(f"sleeping for {TIME_INTERVALL} seconds")
|
|
time.sleep(TIME_INTERVALL)
|
|
except KeyboardInterrupt:
|
|
break
|
|
except Exception:
|
|
logger.exception("unexpected error")
|
|
time.sleep(60)
|