Mar 18, 2025

Mar 18, 2025

Mar 18, 2025

Automated Price Monitoring with Airtop and Python: Never Miss a Competitor's Price Change

Automated Price Monitoring with Airtop and Python: Never Miss a Competitor's Price Change

Automated Price Monitoring with Airtop and Python: Never Miss a Competitor's Price Change

Written by

.

DevRel Engineer

In today's competitive digital marketplace, staying informed about competitors' pricing strategies is crucial for maintaining a competitive edge. This article will guide you through setting up an automated price monitoring system using Airtop's AI capabilities and Python.

What You'll Learn

  • How to set up the Airtop Python SDK

  • Creating a script to monitor competitors' pricing pages

  • Automating price change detection

  • Implementing a system that compares new pricing with historical data

Prerequisites

Setting Up Your Environment

First, you'll need to install the Airtop Python SDK:

pip install airtop-sdk

Creating the Price Monitoring Script

Let's break down the process of creating a Python script that monitors competitor pricing pages:

Step 1: Import Required Libraries

import asyncio
from airtop import AsyncAirtop
from airtop import SessionConfigV1
from airtop import PageQueryConfig
from airtop.core.api_error import ApiError

Step 2: Configure Your Airtop Client

AIRTOP_API_KEY = "YOUR_API_KEY"  # Replace with your API key from https://portal.airtop.ai/api-keys

Step 3: Create the Main Function

async def run():
    client = None
    session_id = None
    if not AIRTOP_API_KEY or AIRTOP_API_KEY == "YOUR_API_KEY":
        raise Exception("AIRTOP_API_KEY is not set")
    try:
        # Initialize the Airtop client
        client = AsyncAirtop(api_key=AIRTOP_API_KEY)
        # Create a session configuration
        configuration = SessionConfigV1(
            timeout_minutes=10,
        )
        # Create a session
        session = await client.sessions.create(configuration=configuration)
        if not session or hasattr(session, "errors") and session.errors:
            raise Exception(f"Failed to create session: {session.errors}")
        session_id = session.data.id if session.data else None

Step 4: Open the Target Pricing Page

        # Create a browser window
        window = await client.windows.create(session_id, url="https://www.descript.com/pricing")
        if not window.data:
            raise Exception("Failed to create window")
        # Add a wait of 5 secs to allow the page to load
        await asyncio.sleep(5)
        # Get the window ID
        window_id = window.data.window_id

Step 5: Query the Page with AI

This is where the magic happens. We'll use Airtop's AI capabilities to analyze the pricing page:

        # Prompt the page
        prompt_response = await client.windows.page_query(
            session_id=session_id,
            window_id=window_id,
            prompt="[YOUR_PROMPT]",
        )
        if hasattr(prompt_response, "error") and prompt_response.error:
            raise Exception(f"Failed to prompt content: {prompt_response.error}")
        print("Prompt results:", prompt_response.data.model_response)

As a prompt for the above, we could use the following:

This is a pricing page. Please summarize it concisely by including every plan. 
For each plan, list the price and the top 3 features it includes. 
Compare the current plan to the previous plan described below:

Free Plan: $0 - Includes text-based editing, AI tools trial, and 1 hour of transcription per month.
Hobbyist Plan: $10 per person/month (annual) or $24 (monthly) - Offers 10 transcription hours/month, 1080p export, and 20 uses/month of Basic AI suite. 
Creator Plan: $22 per person/month (annual) or $39 (monthly) - Provides 30 transcription hours/month, 4k export, and unlimited use of Basic and Advanced AI suite. 
Business Plan: $55 per person/month (annual) or $70 (monthly) - Includes 40 transcription hours/month, free Basic seats for collaboration, and unlimited access to Professional AI suite. 
Enterprise Plan: Custom pricing - Tailored solutions with enterprise-grade security.

RETURN ONLY 3 FIELDS:

1. TEXT - A textual description of the pricing, including the plan's name, price, and top 3 features.

2. TEXT - If there are significant differences in the PRICES between the previous plan and the current one, 
  summarize the differences concisely in a textual description, focusing only on the changes in prices.

3. STATUS - In a status field, return [DIFF] if the new plan is substantially different from the previous one, 
  [SIMILAR] if they are similar, or [NEW] if the previous pricing is empty.

- important, do not guess or estimate, just report things that are clearly mentioned in pricing page

Step 6: Handle Errors and Clean Up

    except ApiError as e:
        print(f"API Error: {e.status_code} - {e.body}")
    finally:
        # Terminate the session
        if client is not None and session_id is not None:
            await client.sessions.terminate(session_id)
asyncio.run(run())

How It Works

  1. Session Creation: The script initializes an Airtop session with your API key.

  2. Browser Automation: It opens a browser window and navigates to the competitor's pricing page.

  3. AI Analysis: Using Airtop's AI capabilities, it analyzes the pricing page content.

  4. Comparison: The AI compares the current pricing with previously stored pricing data.

  5. Change Detection: It identifies if there are significant changes in pricing or features.

Customizing the Script

Monitor Multiple Competitors

You can easily modify the script to monitor multiple competitors by creating a list of URLs and looping through them:

competitor_urls = [
    "https://www.competitor1.com/pricing",
    "https://www.competitor2.com/pricing",
    "https://www.competitor3.com/pricing"
]
for url in competitor_urls:
    # Create a new window for each URL
    window = await client.windows.create(session_id, url=url)
    # ... rest of the code

Scheduling Regular Checks

For regular monitoring, you can use scheduling libraries like schedule or set up a cron job:

import schedule
import time
def job():
    asyncio.run(run())
# Schedule the job to run every day at 9 AM
schedule.every().day.at("09:00").do(job)
while True:
    schedule.run_pending()
    time.sleep(60)

(optional) Storing and Analyzing Results

To make this system truly useful, you'll want to store the results in a database for historical comparison. You can use any database system, but for this example, we’ll use SQLite.

import sqlite3
async def store_results(competitor_name, pricing_data):
    conn = sqlite3.connect('pricing_monitor.db')
    cursor = conn.cursor()
    
    # Create table if it doesn't exist
    cursor.execute('''
    CREATE TABLE IF NOT EXISTS pricing_history (
        id INTEGER PRIMARY KEY,
        competitor TEXT,
        pricing_data TEXT,
        status TEXT,
        timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
    )
    ''')
    
    # Insert new pricing data
    cursor.execute('''
    INSERT INTO pricing_history (competitor, pricing_data, status)
    VALUES (?, ?, ?)
    ''', (competitor_name, pricing_data, status))
    
    conn.commit()
    conn.close()

(optional) Setting Up Notifications

You can add notifications to alert you when price changes are detected. For this example, we'll be using smtplib, but you can use any notification system you like and customize it to fit your needs:

import smtplib
from email.mime.text import MIMEText
async def send_notification(subject, message):
    msg = MIMEText(message)
    msg['Subject'] = subject
    msg['From'] = 'your-email@example.com'
    msg['To'] = 'recipient@example.com'
    
    server = smtplib.SMTP('smtp.example.com', 587)
    server.starttls()
    server.login('your-email@example.com', 'your-password')
    server.send_message(msg)
    server.quit()

Conclusion

With this Python script, you've created an automated system that monitors your competitors' pricing pages and alerts you to any changes. This allows you to stay competitive and make informed pricing decisions.

By leveraging Airtop's AI capabilities, you can extract structured data from unstructured web pages without complex web scraping or HTML parsing. This makes the system more robust and less prone to breaking when the website layout changes.

When monitoring competitor websites, remember to comply with all legal and ethical considerations, including respecting robots.txt files and terms of service.

Try this script today and never miss a competitor's price change again!

Next Steps

  • Extend the script to capture more detailed information about pricing plans

  • Implement advanced analytics to identify pricing trends over time

  • Create a dashboard to visualize pricing changes across your competitor landscape

Happy monitoring!

Unlock your AI Agents

Free your team up to develop ground-breaking AI Agents, Airtop handles the infrastructure.

Book a demo

Unlock your AI Agents

Free your team up to develop ground-breaking AI Agents, Airtop handles the infrastructure.

Book a Demo

Unlock your
AI Agents

Free your team up to develop ground-breaking AI Agents, Airtop handles the infrastructure.

Book a Demo