codomo-alerts 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codomo_alerts/__init__.py +5 -0
- codomo_alerts/__main__.py +5 -0
- codomo_alerts/catalog.py +219 -0
- codomo_alerts/cli.py +401 -0
- codomo_alerts/client.py +152 -0
- codomo_alerts/codomo.py +477 -0
- codomo_alerts/config.py +370 -0
- codomo_alerts/dashboard.py +204 -0
- codomo_alerts/demo.py +128 -0
- codomo_alerts/mcp_server.py +86 -0
- codomo_alerts/messages.py +109 -0
- codomo_alerts/notify.py +60 -0
- codomo_alerts/runtime.py +62 -0
- codomo_alerts/schedule.py +56 -0
- codomo_alerts/search.py +219 -0
- codomo_alerts/store.py +256 -0
- codomo_alerts/term.py +62 -0
- codomo_alerts/tracker.py +98 -0
- codomo_alerts/upstream.py +93 -0
- codomo_alerts/watcher.py +334 -0
- codomo_alerts/web/app.css +219 -0
- codomo_alerts/web/app.js +211 -0
- codomo_alerts/web/favicon.svg +1 -0
- codomo_alerts/web/index.html +75 -0
- codomo_alerts/wizard.py +161 -0
- codomo_alerts-0.2.2.dist-info/METADATA +372 -0
- codomo_alerts-0.2.2.dist-info/RECORD +30 -0
- codomo_alerts-0.2.2.dist-info/WHEEL +4 -0
- codomo_alerts-0.2.2.dist-info/entry_points.txt +2 -0
- codomo_alerts-0.2.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Does codomo.eu still answer the way this tool expects? Run by maintainers and CI daily.
|
|
2
|
+
|
|
3
|
+
A failure means alerts are probably broken for everyone. A notice means something new
|
|
4
|
+
appeared (a city) that the code should learn about.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
|
|
11
|
+
from . import catalog
|
|
12
|
+
from .client import Client, CodomoError, Maintenance
|
|
13
|
+
from .codomo import contract_key
|
|
14
|
+
from .config import Search
|
|
15
|
+
from .search import _all, fetch
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class Check:
|
|
20
|
+
name: str
|
|
21
|
+
status: str # ok, fail, notice
|
|
22
|
+
detail: str = ""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def run(client: Client | None = None) -> list[Check]:
|
|
26
|
+
client = client or Client(min_gap=2.0)
|
|
27
|
+
checks: list[Check] = []
|
|
28
|
+
|
|
29
|
+
def add(name: str, ok: bool, detail: str = "") -> bool:
|
|
30
|
+
checks.append(Check(name, "ok" if ok else "fail", detail))
|
|
31
|
+
return ok
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
homes, counts = _all(client, "nl", {"publish_mode": "direct_booking"})
|
|
35
|
+
except Maintenance as e:
|
|
36
|
+
add("Homes page answers", False, f"{e} (temporary, try again later)")
|
|
37
|
+
return checks
|
|
38
|
+
except CodomoError as e:
|
|
39
|
+
add("Homes page answers", False, str(e))
|
|
40
|
+
return checks
|
|
41
|
+
add("Homes page answers", True, f"{len(homes)} homes to book directly in the Netherlands")
|
|
42
|
+
if not add("Homes are listed", bool(homes), "" if homes else "0 homes in the whole country is very unusual"):
|
|
43
|
+
return checks
|
|
44
|
+
|
|
45
|
+
complete = [c for c in homes if c.rent and c.city and c.bedrooms is not None and c.photos and c.unit_id]
|
|
46
|
+
add("Home cards have the expected fields", len(complete) == len(homes),
|
|
47
|
+
f"{len(homes) - len(complete)} of {len(homes)} incomplete" if len(complete) != len(homes) else "")
|
|
48
|
+
add("Booking counts add up", counts.booking.get(None, 0) >= counts.booking.get("direct_booking", 0) > 0,
|
|
49
|
+
str(counts.booking))
|
|
50
|
+
|
|
51
|
+
first = homes[0]
|
|
52
|
+
try:
|
|
53
|
+
page = client.unit(first.path)
|
|
54
|
+
add("Home pages can be read", page.basic_rent is not None,
|
|
55
|
+
f"{first.name}: {catalog.contract_label(contract_key(page))}, rent €{page.basic_rent:,.0f}")
|
|
56
|
+
except CodomoError as e:
|
|
57
|
+
add("Home pages can be read", False, str(e))
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
status, kind = client.photo(first.photos[0])
|
|
61
|
+
add("Photos load", status == 200 and kind.startswith("image/"), f"HTTP {status} {first.photos[0]}")
|
|
62
|
+
except CodomoError as e:
|
|
63
|
+
add("Photos load", False, str(e))
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
two = fetch(client, Search(countries=["nl"], bedrooms=[2]), "available")
|
|
67
|
+
add("Filters are applied", all(x.bedrooms == 2 for x in two.values()), f"{len(two)} homes with 2 bedrooms")
|
|
68
|
+
listed = client.cities()
|
|
69
|
+
unknown = sorted(c.name for c in listed if not any(catalog.same_city(c.name, k) for k in catalog.CITIES))
|
|
70
|
+
if unknown:
|
|
71
|
+
checks.append(Check("New cities", "notice", ", ".join(unknown) + " (add them to catalog.py)"))
|
|
72
|
+
except CodomoError as e:
|
|
73
|
+
add("Follow-up pages answer", False, str(e))
|
|
74
|
+
return checks
|
|
75
|
+
|
|
76
|
+
codes = sorted({c.country.lower() for c in listed} - {"nl"}, key=lambda c: (c not in catalog.MARKETS, c))
|
|
77
|
+
for code in codes:
|
|
78
|
+
name = catalog.market_label(code)
|
|
79
|
+
try:
|
|
80
|
+
homes, _ = _all(client, code, {"publish_mode": "direct_booking"})
|
|
81
|
+
add(f"Homes in {name} can be read", True, f"{len(homes)} homes to book directly")
|
|
82
|
+
except CodomoError as e:
|
|
83
|
+
add(f"Homes in {name} can be read", False, str(e))
|
|
84
|
+
if code not in catalog.MARKETS:
|
|
85
|
+
checks.append(Check("New country", "notice", f"{code.upper()} (add it to MARKETS in catalog.py)"))
|
|
86
|
+
return checks
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def markdown(checks: list[Check]) -> str:
|
|
90
|
+
icon = {"ok": "✅", "fail": "❌", "notice": "🆕"}
|
|
91
|
+
lines = ["| | Check | Detail |", "|---|---|---|"]
|
|
92
|
+
lines += [f"| {icon[c.status]} | {c.name} | {c.detail} |" for c in checks]
|
|
93
|
+
return "\n".join(lines) + "\n"
|
codomo_alerts/watcher.py
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"""The loop: check, compare, notify, wait. Backs off when Codomo pushes back."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import logging
|
|
7
|
+
import random
|
|
8
|
+
import threading
|
|
9
|
+
import time
|
|
10
|
+
from collections import defaultdict
|
|
11
|
+
from datetime import datetime, timedelta
|
|
12
|
+
|
|
13
|
+
from . import catalog, messages, schedule
|
|
14
|
+
from .client import Blocked, Changed, Client, CodomoError, RateLimited
|
|
15
|
+
from .config import Config
|
|
16
|
+
from .notify import Notifier
|
|
17
|
+
from .search import Listing, building_name, buildings, contract, discover_cities, fetch
|
|
18
|
+
from .store import Store, iso, parse, to_listing, utcnow
|
|
19
|
+
from .tracker import Result, Tracker
|
|
20
|
+
|
|
21
|
+
log = logging.getLogger("codomo_alerts")
|
|
22
|
+
|
|
23
|
+
DISCOVER_EVERY = timedelta(hours=24)
|
|
24
|
+
BUILDINGS_EVERY = timedelta(hours=6)
|
|
25
|
+
SLOW_FAILURE_NOTICE = timedelta(hours=1)
|
|
26
|
+
ALERT_TTL = timedelta(hours=6) # an alert that can't be sent for this long is dropped
|
|
27
|
+
MAX_PAUSE = 6 * 3600
|
|
28
|
+
PAGES_PER_CHECK = 40 # home pages read per check for the maximum stay
|
|
29
|
+
PAGES_FOR_ALERTS = 10
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Watcher:
|
|
33
|
+
def __init__(self, cfg: Config, store: Store, client: Client | None = None,
|
|
34
|
+
notifier: Notifier | None = None, clock=utcnow, rng: random.Random | None = None):
|
|
35
|
+
self.cfg = cfg
|
|
36
|
+
self.store = store
|
|
37
|
+
self.client = client or Client(cfg.base_url)
|
|
38
|
+
self.notifier = notifier or Notifier(cfg.notify.urls)
|
|
39
|
+
self.tracker = Tracker(store, cfg.search.fingerprint())
|
|
40
|
+
self.clock = clock
|
|
41
|
+
self.rng = rng or random.Random()
|
|
42
|
+
self.stop = threading.Event()
|
|
43
|
+
|
|
44
|
+
# Status shown on the dashboard
|
|
45
|
+
|
|
46
|
+
def status(self, state: str, message: str = "", next_at: datetime | None = None) -> None:
|
|
47
|
+
current = self.store.get("status", {})
|
|
48
|
+
current.update(state=state, message=message, next_check=iso(next_at) if next_at else None,
|
|
49
|
+
window=schedule.window(self.clock()))
|
|
50
|
+
self.store.set("status", current)
|
|
51
|
+
|
|
52
|
+
# Main loop
|
|
53
|
+
|
|
54
|
+
def run(self) -> None:
|
|
55
|
+
self.status("starting")
|
|
56
|
+
while not self.stop.is_set():
|
|
57
|
+
try:
|
|
58
|
+
delay = self.tick()
|
|
59
|
+
except Exception: # the loop itself must survive anything
|
|
60
|
+
log.exception("Unexpected error")
|
|
61
|
+
delay = 300
|
|
62
|
+
self.stop.wait(delay)
|
|
63
|
+
self.status("stopped")
|
|
64
|
+
|
|
65
|
+
def tick(self) -> float:
|
|
66
|
+
now = self.clock()
|
|
67
|
+
pause = parse(self.store.get("pause_until"))
|
|
68
|
+
if pause and now < pause:
|
|
69
|
+
current = self.store.get("status", {})
|
|
70
|
+
if current.get("state") not in ("paused", "retrying"):
|
|
71
|
+
self.status("paused", current.get("message") or "Waiting before the next try", pause)
|
|
72
|
+
self.deliver(now)
|
|
73
|
+
return (pause - now).total_seconds()
|
|
74
|
+
|
|
75
|
+
started, before = time.monotonic(), self.client.requests
|
|
76
|
+
try:
|
|
77
|
+
matching = self.check(now)
|
|
78
|
+
except CodomoError as e:
|
|
79
|
+
self.store.check(False, self._ms(started), None, self.client.requests - before, str(e))
|
|
80
|
+
delay = self.failed(e, now)
|
|
81
|
+
self.deliver(now)
|
|
82
|
+
return delay
|
|
83
|
+
except Exception as e:
|
|
84
|
+
log.exception("Unexpected error")
|
|
85
|
+
self.store.check(False, self._ms(started), None, self.client.requests - before, repr(e))
|
|
86
|
+
self.status("retrying", "Something went wrong, see the logs", now + timedelta(minutes=5))
|
|
87
|
+
self.deliver(now)
|
|
88
|
+
return 300
|
|
89
|
+
|
|
90
|
+
self.store.check(True, self._ms(started), matching, self.client.requests - before)
|
|
91
|
+
self.store.set("status", {**self.store.get("status", {}), "last_check": iso(now)})
|
|
92
|
+
self.recovered(now)
|
|
93
|
+
self.deliver(now)
|
|
94
|
+
self.store.prune()
|
|
95
|
+
delay = schedule.next_delay(self.cfg.schedule, now, self.rng)
|
|
96
|
+
self.status("watching", "", now + timedelta(seconds=delay))
|
|
97
|
+
return delay
|
|
98
|
+
|
|
99
|
+
@staticmethod
|
|
100
|
+
def _ms(started: float) -> int:
|
|
101
|
+
return int((time.monotonic() - started) * 1000)
|
|
102
|
+
|
|
103
|
+
def check(self, now: datetime) -> int:
|
|
104
|
+
search = self.cfg.search
|
|
105
|
+
self.discover(now)
|
|
106
|
+
first = not self.store.get("welcomed")
|
|
107
|
+
seen = self.seen_markets()
|
|
108
|
+
available = self.apply("available", self.resolve(fetch(self.client, search, "available", seen)), now)
|
|
109
|
+
results = [available]
|
|
110
|
+
if available.baseline:
|
|
111
|
+
self.started(available, now)
|
|
112
|
+
if not search.interest:
|
|
113
|
+
self.interest_off()
|
|
114
|
+
elif self.due("interest_checked", now, schedule.interest_due_every(self.cfg.schedule)):
|
|
115
|
+
interest = self.apply("interest", self.resolve(fetch(self.client, search, "interest", seen)), now)
|
|
116
|
+
results.append(interest)
|
|
117
|
+
self.store.set("interest_checked", iso(now))
|
|
118
|
+
if first and interest.baseline and self.cfg.notify.existing_on_start:
|
|
119
|
+
# register-interest homes have no race to lose: on the first run they are sent too
|
|
120
|
+
self.existing("interest", now)
|
|
121
|
+
if self.due("buildings_checked", now, BUILDINGS_EVERY.total_seconds()):
|
|
122
|
+
self.buildings(now)
|
|
123
|
+
self.store.set("buildings_checked", iso(now))
|
|
124
|
+
|
|
125
|
+
self.details([c.listing for r in results for c in r.changes if c.kind != "gone"])
|
|
126
|
+
kinds: dict[str, int] = defaultdict(int)
|
|
127
|
+
for r in results:
|
|
128
|
+
for c in r.changes:
|
|
129
|
+
kinds[c.kind] += 1
|
|
130
|
+
extra = ", ".join(f"{n} {kind}" for kind, n in kinds.items())
|
|
131
|
+
log.info("%d match%s", available.matching, f" ({extra})" if extra else "")
|
|
132
|
+
return available.matching
|
|
133
|
+
|
|
134
|
+
def resolve(self, current: dict[str, Listing]) -> dict[str, Listing]:
|
|
135
|
+
"""Fill in what earlier checks learned. With a contract filter, each new home's own page
|
|
136
|
+
is read for its maximum stay; a home whose page can't be read waits for the next check,
|
|
137
|
+
so a short stay is never announced to someone who wants a long one."""
|
|
138
|
+
for x in current.values():
|
|
139
|
+
self.store.known_details(x)
|
|
140
|
+
wanted = self.cfg.search.contracts
|
|
141
|
+
if not wanted:
|
|
142
|
+
return current
|
|
143
|
+
todo = [x for x in current.values() if x.contract is None]
|
|
144
|
+
self.read_contracts(todo, PAGES_PER_CHECK)
|
|
145
|
+
waiting = sum(x.contract is None for x in todo)
|
|
146
|
+
if waiting:
|
|
147
|
+
log.info("%d home%s wait for the next check to read their contract", waiting,
|
|
148
|
+
"s" if waiting > 1 else "")
|
|
149
|
+
return {k: x for k, x in current.items() if catalog.contract_ok(x.contract, wanted)}
|
|
150
|
+
|
|
151
|
+
def read_contracts(self, listings: list[Listing], budget: int) -> None:
|
|
152
|
+
for x in listings[:budget]:
|
|
153
|
+
key = contract(self.client, x)
|
|
154
|
+
if key:
|
|
155
|
+
x.contract = key
|
|
156
|
+
self.store.save_contract(x.id, key)
|
|
157
|
+
|
|
158
|
+
def apply(self, status: str, current: dict[str, Listing], now: datetime) -> Result:
|
|
159
|
+
with self.store.transaction():
|
|
160
|
+
result = self.tracker.apply(status, current, now)
|
|
161
|
+
for c in result.changes:
|
|
162
|
+
self.store.event(c.kind, c.listing.id, status, c.listing.price, c.detail, at=now)
|
|
163
|
+
return result
|
|
164
|
+
|
|
165
|
+
def due(self, key: str, now: datetime, every: float) -> bool:
|
|
166
|
+
last = parse(self.store.get(key))
|
|
167
|
+
return last is None or (now - last).total_seconds() >= every
|
|
168
|
+
|
|
169
|
+
def details(self, listings: list[Listing]) -> None:
|
|
170
|
+
"""Best effort: an alert without the contract is better than no alert."""
|
|
171
|
+
for x in listings:
|
|
172
|
+
self.store.known_details(x)
|
|
173
|
+
need = [x for x in listings if x.contract is None]
|
|
174
|
+
if need:
|
|
175
|
+
try:
|
|
176
|
+
self.read_contracts(need, PAGES_FOR_ALERTS)
|
|
177
|
+
except CodomoError as e:
|
|
178
|
+
log.info("Couldn't look up all details: %s", e)
|
|
179
|
+
for x in listings:
|
|
180
|
+
self.store.details(x)
|
|
181
|
+
|
|
182
|
+
def started(self, r: Result, now: datetime) -> None:
|
|
183
|
+
summary = self.cfg.search.summary()
|
|
184
|
+
if r.filters_changed:
|
|
185
|
+
self.notifier.send(*messages.search_changed(summary, r.matching))
|
|
186
|
+
return
|
|
187
|
+
if self.store.get("welcomed"):
|
|
188
|
+
return
|
|
189
|
+
self.notifier.send(*messages.welcome(summary, r.matching))
|
|
190
|
+
self.store.set("welcomed", iso(now))
|
|
191
|
+
if self.cfg.notify.existing_on_start and r.matching:
|
|
192
|
+
self.existing("available", now)
|
|
193
|
+
|
|
194
|
+
def existing(self, status: str, now: datetime) -> None:
|
|
195
|
+
"""Announce what already matches (first run with notify.existing_on_start)."""
|
|
196
|
+
rows = self.store.active(status).values()
|
|
197
|
+
kind = "interest" if status == "interest" else "new"
|
|
198
|
+
for row in rows:
|
|
199
|
+
self.store.event(kind, row["id"], status, row["price"], at=now)
|
|
200
|
+
self.details([to_listing(row) for row in rows])
|
|
201
|
+
|
|
202
|
+
def interest_off(self) -> None:
|
|
203
|
+
active = self.store.active("interest")
|
|
204
|
+
if active:
|
|
205
|
+
for key in active:
|
|
206
|
+
self.store.retire(key)
|
|
207
|
+
self.store.set("baseline:interest", None)
|
|
208
|
+
|
|
209
|
+
def discover(self, now: datetime) -> None:
|
|
210
|
+
if not self.due("cities_checked", now, DISCOVER_EVERY.total_seconds()):
|
|
211
|
+
return
|
|
212
|
+
try:
|
|
213
|
+
seen = discover_cities(self.client)
|
|
214
|
+
except Changed as e:
|
|
215
|
+
log.debug("City discovery skipped: %s", e)
|
|
216
|
+
seen = {}
|
|
217
|
+
if seen: # a failed read keeps the last list, so countries don't come and go
|
|
218
|
+
self.store.set("cities_seen", seen)
|
|
219
|
+
self.store.set("cities_checked", iso(now))
|
|
220
|
+
|
|
221
|
+
def seen_markets(self) -> list[str]:
|
|
222
|
+
"""Countries codomo.eu listed at the last city check, new ones included."""
|
|
223
|
+
return sorted(set((self.store.get("cities_seen") or {}).values()))
|
|
224
|
+
|
|
225
|
+
def wanted_city(self, city: str, country: str) -> bool:
|
|
226
|
+
search = self.cfg.search
|
|
227
|
+
if any(catalog.same_city(city, c) for c in search.exclude_cities):
|
|
228
|
+
return False
|
|
229
|
+
if search.cities:
|
|
230
|
+
return any(catalog.same_city(city, c) for c in search.cities)
|
|
231
|
+
return country in search.markets(self.seen_markets())
|
|
232
|
+
|
|
233
|
+
def buildings(self, now: datetime) -> None:
|
|
234
|
+
"""New building pages in codomo.eu's sitemap: a building often shows up before its homes
|
|
235
|
+
are on sale. The first scan only learns what exists."""
|
|
236
|
+
first = not self.store.get("buildings_scanned")
|
|
237
|
+
try:
|
|
238
|
+
pages = buildings(self.client)
|
|
239
|
+
except CodomoError as e:
|
|
240
|
+
log.info("Skipped the new building check: %s", e)
|
|
241
|
+
return
|
|
242
|
+
for country, city_slug, slug in pages:
|
|
243
|
+
city = catalog.city_label(city_slug)
|
|
244
|
+
url = f"{self.client.base_url}/homes/{country}/en/{city_slug}/{slug}"
|
|
245
|
+
name = building_name(slug)
|
|
246
|
+
fresh = self.store.building(f"{country}/{city_slug}/{slug}", name, city, url, now)
|
|
247
|
+
if fresh and not first and self.wanted_city(city, country):
|
|
248
|
+
detail = json.dumps({"name": name, "city": city, "url": url})
|
|
249
|
+
self.store.event("building", None, detail=detail, at=now, notified=False)
|
|
250
|
+
self.store.set("buildings_scanned", iso(now))
|
|
251
|
+
|
|
252
|
+
# Notifications
|
|
253
|
+
|
|
254
|
+
def deliver(self, now: datetime) -> None:
|
|
255
|
+
try:
|
|
256
|
+
self._deliver(now)
|
|
257
|
+
except Exception:
|
|
258
|
+
log.exception("Delivering alerts failed")
|
|
259
|
+
|
|
260
|
+
def _deliver(self, now: datetime) -> None:
|
|
261
|
+
if schedule.quiet(self.cfg.notify.quiet_hours, now):
|
|
262
|
+
return
|
|
263
|
+
dropped = self.store.expire(now - ALERT_TTL)
|
|
264
|
+
if dropped:
|
|
265
|
+
log.warning("Dropped %d alert%s that couldn't be sent for hours", dropped, "s" if dropped > 1 else "")
|
|
266
|
+
rows = self.store.pending(now - ALERT_TTL)
|
|
267
|
+
if not rows:
|
|
268
|
+
return
|
|
269
|
+
new_buildings = [r for r in rows if r["kind"] == "building"]
|
|
270
|
+
rows = [r for r in rows if r["kind"] != "building"]
|
|
271
|
+
stale = [r["event_id"] for r in rows if not r["active"]]
|
|
272
|
+
if stale:
|
|
273
|
+
self.store.mark_sent(stale) # taken while we waited, nothing to act on
|
|
274
|
+
rows = [r for r in rows if r["active"]]
|
|
275
|
+
interest = [r for r in rows if r["kind"] == "interest"]
|
|
276
|
+
others = [r for r in rows if r["kind"] != "interest"]
|
|
277
|
+
for group in (others, interest):
|
|
278
|
+
if not group:
|
|
279
|
+
continue
|
|
280
|
+
if len(group) > self.cfg.notify.digest_after:
|
|
281
|
+
title, body = messages.digest([(r["kind"], to_listing(r)) for r in group], now)
|
|
282
|
+
self._sent([r["event_id"] for r in group], self.notifier.send(title, body))
|
|
283
|
+
else:
|
|
284
|
+
for r in group:
|
|
285
|
+
title, body = messages.alert(r["kind"], to_listing(r), r["detail"], now)
|
|
286
|
+
self._sent([r["event_id"]], self.notifier.send(title, body))
|
|
287
|
+
for r in new_buildings:
|
|
288
|
+
info = json.loads(r["detail"])
|
|
289
|
+
title, body = messages.building(info["name"], info.get("city") or "", info.get("url"))
|
|
290
|
+
self._sent([r["event_id"]], self.notifier.send(title, body))
|
|
291
|
+
|
|
292
|
+
def _sent(self, ids: list[int], ok: bool) -> None:
|
|
293
|
+
(self.store.mark_sent if ok else self.store.mark_failed)(ids)
|
|
294
|
+
|
|
295
|
+
# Trouble
|
|
296
|
+
|
|
297
|
+
def failed(self, e: CodomoError, now: datetime) -> float:
|
|
298
|
+
n = int(self.store.get("failures", 0)) + 1
|
|
299
|
+
self.store.set("failures", n)
|
|
300
|
+
since = parse(self.store.get("failing_since")) or now
|
|
301
|
+
self.store.set("failing_since", iso(since))
|
|
302
|
+
if isinstance(e, RateLimited):
|
|
303
|
+
delay = e.retry_after or 300 * 2 ** (n - 1)
|
|
304
|
+
delay = min(delay, 3600 if not e.retry_after else MAX_PAUSE)
|
|
305
|
+
elif isinstance(e, Blocked):
|
|
306
|
+
delay = min(MAX_PAUSE, 1800 * 2 ** (n - 1))
|
|
307
|
+
elif isinstance(e, Changed):
|
|
308
|
+
delay = min(MAX_PAUSE, 900 * 2 ** (n - 1))
|
|
309
|
+
else:
|
|
310
|
+
delay = min(900, 60 * 2 ** (n - 1))
|
|
311
|
+
delay = max(60.0, float(delay))
|
|
312
|
+
until = now + timedelta(seconds=delay)
|
|
313
|
+
self.store.set("pause_until", iso(until))
|
|
314
|
+
self.status("paused" if isinstance(e, Blocked | RateLimited) else "retrying", str(e), until)
|
|
315
|
+
log.warning("%s. Next try at %s", e, f"{schedule.local(until):%H:%M}")
|
|
316
|
+
|
|
317
|
+
serious = isinstance(e, Blocked | Changed) or (isinstance(e, RateLimited) and delay >= 900)
|
|
318
|
+
if (self.cfg.notify.health and not self.store.get("health_notified")
|
|
319
|
+
and (serious or now - since >= SLOW_FAILURE_NOTICE)
|
|
320
|
+
and not schedule.quiet(self.cfg.notify.quiet_hours, now)):
|
|
321
|
+
msg = messages.broken(str(e)) if isinstance(e, Changed) else messages.paused(str(e), until)
|
|
322
|
+
if self.notifier.send(*msg):
|
|
323
|
+
self.store.set("health_notified", True)
|
|
324
|
+
return delay
|
|
325
|
+
|
|
326
|
+
def recovered(self, now: datetime) -> None:
|
|
327
|
+
if not self.store.get("failures"):
|
|
328
|
+
return
|
|
329
|
+
if (self.store.get("health_notified") and self.cfg.notify.health
|
|
330
|
+
and not schedule.quiet(self.cfg.notify.quiet_hours, now)):
|
|
331
|
+
self.notifier.send(*messages.resumed())
|
|
332
|
+
for key in ("failures", "failing_since", "health_notified", "pause_until"):
|
|
333
|
+
self.store.set(key, None)
|
|
334
|
+
log.info("Codomo answers again")
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bg: #08080a;
|
|
3
|
+
--fg: #f4f4f5;
|
|
4
|
+
--muted: #8e8e96;
|
|
5
|
+
--faint: #55555c;
|
|
6
|
+
--glass: rgba(255, 255, 255, 0.045);
|
|
7
|
+
--glass-hover: rgba(255, 255, 255, 0.075);
|
|
8
|
+
--line: rgba(255, 255, 255, 0.08);
|
|
9
|
+
--line-strong: rgba(255, 255, 255, 0.16);
|
|
10
|
+
--blob: rgba(255, 255, 255, 0.10);
|
|
11
|
+
--cell: rgba(255, 255, 255, 0.05);
|
|
12
|
+
--shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 20px 50px -30px rgba(0, 0, 0, 0.9);
|
|
13
|
+
--radius: 18px;
|
|
14
|
+
--sans: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@media (prefers-color-scheme: light) {
|
|
18
|
+
:root {
|
|
19
|
+
--bg: #f2f2f3;
|
|
20
|
+
--fg: #0c0c0e;
|
|
21
|
+
--muted: #66666e;
|
|
22
|
+
--faint: #a0a0a8;
|
|
23
|
+
--glass: rgba(255, 255, 255, 0.55);
|
|
24
|
+
--glass-hover: rgba(255, 255, 255, 0.8);
|
|
25
|
+
--line: rgba(0, 0, 0, 0.07);
|
|
26
|
+
--line-strong: rgba(0, 0, 0, 0.14);
|
|
27
|
+
--blob: rgba(0, 0, 0, 0.07);
|
|
28
|
+
--cell: rgba(0, 0, 0, 0.05);
|
|
29
|
+
--shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 20px 40px -30px rgba(0, 0, 0, 0.35);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
* { box-sizing: border-box; }
|
|
34
|
+
|
|
35
|
+
html, body { margin: 0; }
|
|
36
|
+
|
|
37
|
+
body {
|
|
38
|
+
min-height: 100vh;
|
|
39
|
+
background: var(--bg);
|
|
40
|
+
color: var(--fg);
|
|
41
|
+
font: 15px/1.5 var(--sans);
|
|
42
|
+
-webkit-font-smoothing: antialiased;
|
|
43
|
+
font-feature-settings: "tnum" 1, "cv11" 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
a { color: inherit; text-decoration: none; }
|
|
47
|
+
|
|
48
|
+
.backdrop { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
|
|
49
|
+
.backdrop span {
|
|
50
|
+
position: absolute;
|
|
51
|
+
border-radius: 50%;
|
|
52
|
+
background: radial-gradient(circle, var(--blob), transparent 65%);
|
|
53
|
+
filter: blur(30px);
|
|
54
|
+
}
|
|
55
|
+
.backdrop span:nth-child(1) { width: 60vw; height: 60vw; top: -25vw; left: -15vw; }
|
|
56
|
+
.backdrop span:nth-child(2) { width: 50vw; height: 50vw; top: 30vh; right: -20vw; }
|
|
57
|
+
.backdrop span:nth-child(3) { width: 40vw; height: 40vw; bottom: -20vw; left: 25vw; opacity: 0.7; }
|
|
58
|
+
|
|
59
|
+
main {
|
|
60
|
+
position: relative;
|
|
61
|
+
z-index: 1;
|
|
62
|
+
max-width: 1080px;
|
|
63
|
+
margin: 0 auto;
|
|
64
|
+
padding: 28px 20px 48px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
|
|
68
|
+
|
|
69
|
+
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; }
|
|
70
|
+
.brand svg { width: 22px; height: 22px; fill: var(--fg); }
|
|
71
|
+
.brand b { font-weight: 600; }
|
|
72
|
+
.brand span { color: var(--muted); }
|
|
73
|
+
.brand span b { color: var(--fg); }
|
|
74
|
+
|
|
75
|
+
.pill {
|
|
76
|
+
display: inline-flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
gap: 8px;
|
|
79
|
+
padding: 7px 14px;
|
|
80
|
+
border-radius: 999px;
|
|
81
|
+
background: var(--glass);
|
|
82
|
+
border: 1px solid var(--line);
|
|
83
|
+
backdrop-filter: blur(16px) saturate(140%);
|
|
84
|
+
-webkit-backdrop-filter: blur(16px) saturate(140%);
|
|
85
|
+
font-size: 13px;
|
|
86
|
+
color: var(--muted);
|
|
87
|
+
white-space: nowrap;
|
|
88
|
+
}
|
|
89
|
+
.pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
|
|
90
|
+
.pill.on i { background: var(--fg); box-shadow: 0 0 0 0 var(--line-strong); animation: pulse 2.4s infinite; }
|
|
91
|
+
.pill.on span { color: var(--fg); }
|
|
92
|
+
@keyframes pulse {
|
|
93
|
+
0% { box-shadow: 0 0 0 0 var(--line-strong); }
|
|
94
|
+
70% { box-shadow: 0 0 0 8px transparent; }
|
|
95
|
+
100% { box-shadow: 0 0 0 0 transparent; }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.search { margin: 26px 0 18px; font-size: 22px; letter-spacing: -0.02em; font-weight: 500; }
|
|
99
|
+
|
|
100
|
+
.glass {
|
|
101
|
+
background: var(--glass);
|
|
102
|
+
border: 1px solid var(--line);
|
|
103
|
+
border-radius: var(--radius);
|
|
104
|
+
backdrop-filter: blur(20px) saturate(140%);
|
|
105
|
+
-webkit-backdrop-filter: blur(20px) saturate(140%);
|
|
106
|
+
box-shadow: var(--shadow);
|
|
107
|
+
padding: 18px 20px;
|
|
108
|
+
margin-bottom: 16px;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
|
|
112
|
+
.stat { padding: 16px 18px; margin: 0; }
|
|
113
|
+
.stat small { display: block; color: var(--muted); font-size: 12.5px; }
|
|
114
|
+
.stat strong { display: block; font-size: 28px; font-weight: 500; letter-spacing: -0.03em; margin-top: 2px; }
|
|
115
|
+
.stat strong.none { font-size: 15px; color: var(--faint); font-weight: 400; margin-top: 12px; }
|
|
116
|
+
|
|
117
|
+
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
|
|
118
|
+
h2 { margin: 0; font-size: 13px; font-weight: 500; letter-spacing: 0.02em; color: var(--muted); }
|
|
119
|
+
.muted { color: var(--faint); font-size: 12.5px; }
|
|
120
|
+
|
|
121
|
+
.list { list-style: none; margin: 0; padding: 0; }
|
|
122
|
+
.list li { border-top: 1px solid var(--line); }
|
|
123
|
+
.list li:first-child { border-top: 0; }
|
|
124
|
+
.list a, .list .row {
|
|
125
|
+
display: flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
justify-content: space-between;
|
|
128
|
+
gap: 16px;
|
|
129
|
+
padding: 12px 10px;
|
|
130
|
+
margin: 0 -10px;
|
|
131
|
+
border-radius: 12px;
|
|
132
|
+
transition: background 0.15s;
|
|
133
|
+
}
|
|
134
|
+
.list a:hover { background: var(--glass-hover); }
|
|
135
|
+
.list .name { font-weight: 500; }
|
|
136
|
+
.list .meta { color: var(--muted); font-size: 13px; }
|
|
137
|
+
.list .side { text-align: right; white-space: nowrap; }
|
|
138
|
+
.list .price { font-weight: 500; }
|
|
139
|
+
.list .when { color: var(--faint); font-size: 12.5px; }
|
|
140
|
+
.list.compact a, .list.compact .row { padding: 9px 10px; }
|
|
141
|
+
.empty { color: var(--faint); padding: 14px 0 6px; margin: 0; }
|
|
142
|
+
|
|
143
|
+
.grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; align-items: start; }
|
|
144
|
+
.grid > *, .stack > * { min-width: 0; } /* long names truncate instead of widening the page */
|
|
145
|
+
.grid .glass { margin-bottom: 0; }
|
|
146
|
+
.stack { display: grid; gap: 16px; }
|
|
147
|
+
|
|
148
|
+
.feed { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow: auto; }
|
|
149
|
+
.feed li { display: grid; grid-template-columns: 86px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
|
|
150
|
+
.feed li:first-child { border-top: 0; }
|
|
151
|
+
.feed .tag { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
|
|
152
|
+
.feed .tag.hot { color: var(--fg); }
|
|
153
|
+
.feed .what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
154
|
+
.feed .what span { color: var(--muted); }
|
|
155
|
+
.feed time { color: var(--faint); font-size: 12px; white-space: nowrap; }
|
|
156
|
+
|
|
157
|
+
.heat { display: grid; grid-template-columns: 30px repeat(24, minmax(0, 1fr)); gap: 3px; font-size: 10.5px; color: var(--faint); }
|
|
158
|
+
.heat b { font-weight: 400; align-self: center; }
|
|
159
|
+
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--cell); }
|
|
160
|
+
.heat .h { text-align: center; }
|
|
161
|
+
.heat-note { margin: 10px 0 0; color: var(--faint); font-size: 12.5px; }
|
|
162
|
+
|
|
163
|
+
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
|
164
|
+
.bars li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 13.5px; }
|
|
165
|
+
.bars .bar { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--cell); overflow: hidden; }
|
|
166
|
+
.bars .bar span { display: block; height: 100%; background: var(--fg); opacity: 0.75; border-radius: 4px; }
|
|
167
|
+
|
|
168
|
+
footer { display: flex; justify-content: space-between; gap: 16px; margin-top: 28px; color: var(--faint); font-size: 12.5px; }
|
|
169
|
+
footer a:hover { color: var(--fg); }
|
|
170
|
+
|
|
171
|
+
.star {
|
|
172
|
+
position: fixed;
|
|
173
|
+
right: 18px;
|
|
174
|
+
bottom: calc(18px + env(safe-area-inset-bottom));
|
|
175
|
+
z-index: 5;
|
|
176
|
+
display: flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
border-radius: 999px;
|
|
179
|
+
background: var(--glass);
|
|
180
|
+
border: 1px solid var(--line);
|
|
181
|
+
backdrop-filter: blur(16px) saturate(140%);
|
|
182
|
+
-webkit-backdrop-filter: blur(16px) saturate(140%);
|
|
183
|
+
box-shadow: var(--shadow);
|
|
184
|
+
font-size: 13px;
|
|
185
|
+
color: var(--muted);
|
|
186
|
+
transition: opacity 0.3s, transform 0.3s;
|
|
187
|
+
}
|
|
188
|
+
.star a { display: flex; align-items: center; gap: 7px; padding: 8px 6px 8px 13px; border-radius: 999px; transition: color 0.15s; }
|
|
189
|
+
.star a:hover, .star a:focus-visible { color: var(--fg); }
|
|
190
|
+
.star svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linejoin: round; transition: fill 0.15s; }
|
|
191
|
+
.star a:hover svg, .star a:focus-visible svg { fill: currentColor; }
|
|
192
|
+
.star button { border: 0; background: none; color: var(--faint); font: inherit; font-size: 15px; line-height: 1; padding: 6px 12px 7px 6px; cursor: pointer; }
|
|
193
|
+
.star button:hover, .star button:focus-visible { color: var(--fg); }
|
|
194
|
+
.star.gone { opacity: 0; transform: translateY(8px); pointer-events: none; }
|
|
195
|
+
.star[hidden] { display: none; }
|
|
196
|
+
@media print { .star { display: none; } }
|
|
197
|
+
|
|
198
|
+
@media (max-width: 860px) {
|
|
199
|
+
.stats { grid-template-columns: repeat(2, 1fr); }
|
|
200
|
+
.grid { grid-template-columns: 1fr; }
|
|
201
|
+
.search { font-size: 19px; }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@media (max-width: 520px) {
|
|
205
|
+
main { padding: 20px 14px 40px; }
|
|
206
|
+
.brand { font-size: 15px; gap: 8px; }
|
|
207
|
+
.pill { min-width: 0; padding: 6px 12px; }
|
|
208
|
+
.pill span { max-width: 44vw; overflow: hidden; text-overflow: ellipsis; }
|
|
209
|
+
.list a, .list .row { align-items: flex-start; }
|
|
210
|
+
.feed li { grid-template-columns: 72px minmax(0, 1fr); }
|
|
211
|
+
.feed time { grid-column: 2; }
|
|
212
|
+
footer { flex-direction: column; padding-bottom: 56px; }
|
|
213
|
+
.star { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
|
|
214
|
+
.star .long { display: none; }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
@media (prefers-reduced-motion: reduce) {
|
|
218
|
+
.pill.on i { animation: none; }
|
|
219
|
+
}
|