docs(examples): rewrite discord example with the new configuration

This commit is contained in:
etienne-hd
2026-03-07 15:59:33 +01:00
parent d4e76c75af
commit f2a63ec7ff
3 changed files with 28 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
from model import Search, Parameters
import lbc
from .handler import handle
location = lbc.City(
lat=48.85994982004764,
lng=2.33801967847424,
radius=10_000, # 10 km
city="Paris"
)
CONFIG = [
Search(
name="Location Paris",
parameters=Parameters(
text="maison",
locations=[location],
category=lbc.Category.IMMOBILIER,
square=[200, 400],
price=[300_000, 700_000]
),
delay=60 * 5, # Check every 5 minutes
handler=handle
),
]

View File

@@ -0,0 +1,50 @@
import lbc
import requests
from datetime import datetime
from typing import Final
WEBHOOK_URL: Final[str] = ...
def handle(ad: lbc.Ad, search_name: str) -> None:
timestamp = datetime.strptime(ad.index_date, "%Y-%m-%d %H:%M:%S").timestamp()
payload = {
"content": None,
"embeds": [
{
"title": ad.title,
"description": f"```{ad.body[:4087]}...```" if len(ad.body) >= 4090 else f"```{ad.body[:4090]}```",
"url": ad.url,
"color": 14381568,
"author": {
"name": ad.user.name,
"icon_url": ad.user.profile_picture
},
"image": {
"url": ad.images[0] if ad.images else None
},
"fields": [
{
"name": "🕒 Publication",
"value": f"<t:{int(timestamp)}:R>",
"inline": True
},
{
"name": "💰 Price",
"value": f"`{ad.price}€`",
"inline": True
},
{
"name": "📍 Location",
"value": f"`{ad.location.city_label}`",
"inline": True
}
],
}
],
"username": search_name,
"attachments": []
}
response = requests.post(WEBHOOK_URL, json=payload)
response.raise_for_status()