Building a Property Price-Drop Monitoring and Email Alert System with an AI Coding Assistant

    This article explains a practical division of labor for building a real estate price-drop monitoring system: an AI coding assistant handles business logic such as requirement breakdown, data processing, storage, and notifications, while a managed collection API handles access-layer issues such as proxies, rate limits, CAPTCHAs, and JavaScript rendering. Using an example that monitors listings in a selected city and price range, detects daily price drops, and sends email alerts, it covers system architecture, collaboration methods for AI coding assistants, core code structure, retry and validation strategies, testing, and compliance considerations.

    1. Background: Why AI Coding Assistants Need Collection APIs

    Intelligent coding tools have moved from single-turn code completion to Agent-style tools that can read project context, plan autonomously, and execute multi-step tasks. For developers, the main value of these tools is reducing repetitive work: generating project skeletons, completing functions, debugging errors, and writing tests.

    Data collection applications, however, often get stuck at a different stage. An Agent can write code to access a web page, but real-world collection encounters IP restrictions, rate limits, CAPTCHAs, and pages rendered dynamically by JavaScript. These issues are unrelated to business logic, yet they determine whether a script can run reliably. Building a proxy pool, solving CAPTCHAs, and simulating browser environments all require ongoing investment.

    A more practical division of labor is therefore: the AI coding assistant is responsible for business code, including requirement breakdown, data processing, storage, and notification; a managed collection API is responsible for interacting with target sites and hiding access-layer technical details. This article uses the example of “monitoring listings in a certain city and price range, filtering listings with price drops for the day, and sending email alerts” to show how this division works in practice.

    2. Requirement Breakdown and System Architecture

    2.1 Functional Requirements

    The system input and output are simple:

    • Input: target city, minimum price, and maximum price.
    • Output: structured information about listings with price drops for the day (address, price, area, listing link, etc.), plus a price-drop alert email.

    2.2 Processing Flow

    The entire flow can be divided into five stages:

    1. Collection: request listing lists by city or keyword and obtain raw data.
    2. Parsing: normalize returned results into a consistent field structure, for example converting prices to numeric types and standardizing area units.
    3. Storage: write each collected price snapshot to the database and retain historical records.
    4. Detection: compare with the previous snapshot and filter out listings whose prices have decreased.
    5. Notification: summarize listings with price drops and send an email.

    2.3 Architecture Diagram

    1. Scheduled task (once per day)
    2. │
    3. ▼
    4. Collection module ──► Managed collection API (handles proxies, CAPTCHAs, rendering)
    5. │
    6. ▼
    7. Parsing module ──► Field normalization
    8. │
    9. ▼
    10. Storage module ──► Price snapshot table (historical records)
    11. │
    12. ▼
    13. Detection module ──► List of listings with price drops
    14. │
    15. ▼
    16. Notification module ──► Email delivery

    The benefit of this layered approach is that each module can be replaced or tested independently. If other cities or data sources need to be added later, only the collection and parsing modules need to be changed; the detection and notification logic does not need to be modified.

    3. Data Collection Layer: Why Choose a Managed API

    3.1 Main Difficulties of Self-Built Collection

    When accessing web pages directly with code, common problems include:

    • IP access restrictions: requests from the same address at too high a frequency may be limited, requiring rotation of outbound addresses.
    • CAPTCHAs: after risk control is triggered, the page may require human verification.
    • Dynamic rendering: listing lists are loaded by frontend scripts, and the target data may not be present in the raw HTML.
    • Page structure changes: after a site redesign, parsing rules based on fixed selectors may fail.

    Solving these issues one by one often requires more work than the business code itself.

    3.2 Responsibility Boundary of Managed APIs

    Managed web collection APIs usually provide the following capabilities:

    • Initiating collection requests by keyword or page URL;
    • Completing rendering and access-layer handling on the server side;
    • Returning structured or semi-structured data.

    Before use, you should confirm the specific parameters, return fields, and call limits in the API documentation. Do not assume field names based on experience. The example code in this article is only for structural illustration; actual fields must follow the API documentation.

    3.3 Selection and Compliance Principles

    When choosing a collection solution, evaluate it from the following dimensions:

    • Stability: whether success rates and timeout situations are acceptable;
    • Field completeness: whether key fields such as price, address, and area are complete;
    • Compliance terms: whether the terms of service allow the intended use and whether data can be used for personal research or authorized scenarios;
    • Cost structure: whether the billing method and usage estimate match the project scale; specific rules should be verified with the service provider.

    Regardless of the solution chosen, you should comply with the target site’s terms of service and robots protocol, control request frequency, and avoid placing additional burden on the site.

    4. Methods for Collaborating with AI Coding Assistants

    The effectiveness of an AI coding assistant in a project depends largely on the quality of the input context. The following practices help improve the usability of generated code.

    4.1 Provide Complete Context

    It is recommended to include the following materials in the project:

    • Official sample code or request format documentation for the collection API;
    • Documentation describing returned fields;
    • Requirement descriptions, including input parameters, output format, and exception scenarios;
    • Project directory conventions and dependency versions.

    The more specific the context, the closer the generated skeleton will be to actual requirements.

    4.2 Staged Prompting

    It is not recommended to request all functionality at once. Proceed in the following order:

    1. First generate the project skeleton and configuration files;
    2. Implement the collection and parsing modules, and verify them with a real returned sample;
    3. Implement storage and price-drop detection;
    4. Implement email notification and scheduled tasks;
    5. Add exception handling and unit tests.

    Run the code after each step and confirm the result is correct before moving to the next step. This can significantly reduce rework.

    4.3 Key Points for Manual Review

    AI-generated code should be checked with focus on the following:

    • Whether secrets are hardcoded in code or logs;
    • Whether field type conversions are correct, such as converting price strings to numbers;
    • Whether null values and missing fields are handled;
    • Whether boundary conditions for price-drop detection are correct;
    • Whether email content contains unnecessary sensitive information.

    5. Core Code Implementation

    The following code is for structural illustration. Module and function names are placeholders; actual implementations should replace them with the fields and call methods from the API documentation.

    5.1 Configuration Management

    Secrets and email information are read from environment variables and are not written into the code repository.

    1. import os
    2. API_KEY = os.environ["COLLECTOR_API_KEY"]
    3. SMTP_HOST = os.environ["SMTP_HOST"]
    4. SMTP_USER = os.environ["SMTP_USER"]
    5. SMTP_PASSWORD = os.environ["SMTP_PASSWORD"]
    6. NOTIFY_TO = os.environ["NOTIFY_TO"]

    5.2 Collection and Normalization

    1. def fetch_listings(city: str, price_min: int, price_max: int) -> list[dict]:
    2. """Call the managed collection API and return a normalized list of listings."""
    3. raw = collector_client.query(
    4. api_key=API_KEY,
    5. keyword=city,
    6. # How to pass the price range depends on the API documentation
    7. )
    8. listings = []
    9. for item in raw.get("results", []):
    10. price = to_int(item.get("price"))
    11. if price is None or not (price_min <= price <= price_max):
    12. continue
    13. listings.append({
    14. "listing_id": str(item["id"]),
    15. "address": item.get("address", "").strip(),
    16. "price": price,
    17. "area": to_float(item.get("area")),
    18. "url": item.get("url"),
    19. })
    20. return listings

    The normalization stage needs to handle two types of issues: price strings must be converted to integers, and missing fields must have default handling. This allows subsequent detection logic to rely on stable data types.

    5.3 Snapshot Storage

    Each collection saves a price snapshot instead of only overwriting the latest value. This is necessary to determine the direction of price changes.

    1. CREATE TABLE price_snapshot (
    2. listing_id VARCHAR(64) NOT NULL,
    3. price INTEGER NOT NULL,
    4. captured_at DATE NOT NULL,
    5. PRIMARY KEY (listing_id, captured_at)
    6. );

    Using the listing ID and collection date as a composite primary key allows repeated runs on the same day to use insert or update statements to avoid duplicate records.

    5.4 Price-Drop Detection

    1. def find_price_drops(today: list[dict], yesterday_prices: dict[str, int],
    2. min_drop_ratio: float = 0.01) -> list[dict]:
    3. """Compare with the previous day's prices and return listings whose drop exceeds the threshold."""
    4. drops = []
    5. for item in today:
    6. prev = yesterday_prices.get(item["listing_id"])
    7. if prev is None or prev <= 0:
    8. continue # New listings have no comparison baseline and are handled separately
    9. drop_ratio = (prev - item["price"]) / prev
    10. if drop_ratio >= min_drop_ratio:
    11. drops.append({**item, "previous_price": prev, "drop_ratio": drop_ratio})
    12. return drops

    Detection requires clarifying two boundaries: first, new listings without historical prices cannot be judged as price drops and should be classified separately; second, a minimum drop threshold should be set to avoid generating a large number of noisy alerts due to small fluctuations.

    5.5 Email Notification

    1. def send_digest(drops: list[dict]) -> None:
    2. if not drops:
    3. return # Do not send an email when there are no listings with price drops
    4. lines = []
    5. for d in drops:
    6. lines.append(
    7. f"{d['address']} {d['previous_price']} -> {d['price']} {d['url']}"
    8. )
    9. body = "\n".join(lines)
    10. notifier.send(
    11. host=SMTP_HOST,
    12. user=SMTP_USER,
    13. password=SMTP_PASSWORD,
    14. to=NOTIFY_TO,
    15. subject=f"Listings with price drops today: {len(drops)}",
    16. body=body,
    17. )

    The email content contains only the fields required by the business. When there are no listings with price drops, no email is sent, avoiding disruption to users.

    5.6 Scheduled Execution

    It is recommended to trigger the main program once per day through the operating system’s scheduled tasks or the container platform’s scheduling feature, rather than using an infinite loop inside the script. The scheduling method is tied to the runtime environment and should be selected according to the deployment environment.

    6. Exception Handling and Quality Assurance

    6.1 Retry and Backoff

    Network requests may fail due to timeouts or temporary rate limiting. An exponential backoff retry strategy should be adopted, with a maximum number of retries. After exceeding the limit, log the error and exit; do not wait indefinitely.

    1. import time
    2. def with_retry(func, max_attempts: int = 3, base_delay: float = 2.0):
    3. for attempt in range(1, max_attempts + 1):
    4. try:
    5. return func()
    6. except TimeoutError:
    7. if attempt == max_attempts:
    8. raise
    9. time.sleep(base_delay * (2 ** (attempt - 1)))

    6.2 Result Validation

    An empty collection result does not necessarily mean there are no listings; it may also indicate an API exception or a page structure change. The system should validate the following situations:

    • The number of returned records has dropped significantly compared with history, triggering an alert;
    • The missing rate of key fields exceeds a threshold, logging the issue and pausing detection;
    • The proportion of price parsing failures is abnormal, prompting a check of field mappings.

    6.3 Testing

    Use saved real response samples as test data and write unit tests that do not depend on the network, covering the following scenarios: normal price decrease, price increase, unchanged price, new listing, and empty price field. After tests pass, connect the system to scheduled tasks to reduce production issues.

    7. Compliance and Risk Notes

    Automated collection involves data sources and personal information. Before development, confirm the following:

    • Whether the purpose complies with the target site’s terms of service;
    • Whether the data is used only for personal research, authorized analysis, or internal decision-making, and whether it involves external distribution;
    • Whether the request frequency is reasonable and whether it will place obvious pressure on the site;
    • If the data contains contact information or personally identifiable information, storage and distribution should be avoided, and local data protection regulations should be followed.

    A technical solution can address access issues, but it cannot replace compliance judgment. Before the project goes live, it is recommended that the responsible person confirm the data usage in writing.

    8. Summary and Extension Directions

    The core idea of this article is division of labor: the AI coding assistant is responsible for generating and iterating business code, the managed collection API is responsible for complex access-layer issues, and the developer is responsible for requirement definition, result validation, and compliance judgment. By proceeding with requirement breakdown, staged development, and step-by-step validation, even a small team can complete a usable monitoring system in a relatively short time.

    On this basis, the system can be extended in the following directions:

    • Support batch configuration for multiple cities and multiple price ranges;
    • Connect snapshot data to a simple dashboard to observe regional price trends;
    • Add filters by dimensions such as area and layout;
    • Extend email notifications to messaging groups or mobile push notifications.

    Each extension should maintain clear module boundaries so that collection, detection, and notification can evolve independently.