Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
1
Indexable
Never
from flask import Flask, render_template
import requests
import time
from cassandra.cluster import Cluster

app = Flask(__name__)

def compare_response(url):
    response1 = requests.get(url)
    time.sleep(60)  # Wait for 60 seconds
    response2 = requests.get(url)
    
    if response1.content == response2.content:
        return f"No change detected in response body for {url}"
    else:
        return f"Change detected in response body for {url}"

@app.route('/')
def index():
    # Initialize Cassandra connection
    cluster = Cluster(['127.0.0.1'], port=9042)
    session = cluster.connect('yourkeyspace')

    # Retrieve list of APIs from Cassandra
    query = "SELECT url FROM api_list"
    rows = session.execute(query)
    apis = [row[0] for row in rows]

    # Compare response for each API and store results in a list
    results = []
    for api in apis:
        result = compare_response(api)
        results.append(result)

    # Close Cassandra connection
    session.shutdown()
    cluster.shutdown()

    # Render results using a template
    return render_template('index.html', results=results)

if __name__ == '__main__':
    app.run()