""" بات جستجو املاک — نسخه رایگان Real-Estate Search Bot (Bale) بات‌بان | hi@botban.ir """ import os, json, time, sqlite3, logging from typing import Any import requests from dotenv import load_dotenv load_dotenv() log = logging.getLogger(__name__) TOKEN: str = os.getenv("BALE_BOT_TOKEN", "") BASE_URL: str = f"https://tapi.bale.ai/bot{TOKEN}" DB_PATH: str = os.path.join(os.path.dirname(__file__), "realestate.db") # بارگذاری آگهی‌ها (حداکثر ۲۰ — محدودیت نسخه رایگان) with open(os.path.join(os.path.dirname(__file__), "listings.json"), encoding="utf-8") as f: ALL_LISTINGS: list[dict] = json.load(f)[:20] sessions: dict[int, dict] = {} STEPS = ["type", "city", "min_price", "max_price", "bedrooms"] def format_price(price: int, listing_type: str) -> str: if listing_type == "rent": return f"{price:,} تومان/ماه" b = price / 1_000_000_000 return f"{b:.1f} میلیارد تومان" if b >= 1 else f"{price/1_000_000:.0f} میلیون تومان" def city_keyboard() -> dict: cities = sorted({lst["city"] for lst in ALL_LISTINGS}) buttons = [[{"text": f"🏙️ {c}", "callback_data": f"city:{c}"}] for c in cities] buttons.append([{"text": "📍 سایر شهرها (نسخه حرفه‌ای)", "callback_data": "pro_city"}]) return {"inline_keyboard": buttons} def search_listings(f: dict) -> list[dict]: """فیلتر مرحله‌به‌مرحله آگهی‌ها""" results = [] for lst in ALL_LISTINGS: if lst["type"] != f.get("type"): continue if f.get("city") and lst["city"] != f["city"]: continue min_p = f.get("min_price", 0) max_p = f.get("max_price", 10**15) if not (min_p <= lst["price"] <= max_p): continue beds = f.get("bedrooms", 0) if beds and beds != 4 and lst["bedrooms"] != beds: continue results.append(lst) return results def listing_card_text(lst: dict) -> str: feats = "، ".join(lst.get("features", [])) return ( f"🏠 {lst['neighborhood']}، {lst['city']}\n" f"📐 {lst['area']} متر | 🛏️ {lst['bedrooms']} خواب | طبقه {lst['floor']}\n" f"💰 {format_price(lst['price'], lst['type'])}\n" f"✅ {feats}" ) def send_results(chat_id: int, results: list[dict]) -> None: if not results: send_message(chat_id, "😔 ملکی با این مشخصات پیدا نشد.\n/start برای جستجوی جدید.") return for lst in results[:5]: # حداکثر ۵ نتیجه در نسخه رایگان send_message(chat_id, listing_card_text(lst)) # ... ادامه کد (تا ۱۶۷ خط دیگر) # نسخه کامل + مستندات + دیتابیس → hi@botban.ir