I wanna make it display info on the interactions, the ip and useragent for now from…
- User
I wanna make it display info on the interactions, the ip and useragent for now from flask import Flask, render_template, request, jsonify import sqlite3
app = Flask(name)
def query_database(query, limit, offset): connection = sqlite3.connect('leaks.db') cursor = connection.cursor()
codetry: # Execute the query based on the provided search query, limit, and offset pattern = f"%{query}%" query_sql = "SELECT * FROM data WHERE data LIKE ? LIMIT ? OFFSET ?" cursor.execute(query_sql, (pattern, limit, offset)) # Fetch the results results = cursor.fetchall() # Return the results as a list of dictionaries columns = [col[0] for col in cursor.description] results_list = [dict(zip(columns, row)) for row in results] return results_list except sqlite3.Error as e: # Print the SQLite error for debugging print(f"SQLite error: {e}") return {"error": f"SQLite error: {e}"} finally: connection.close()@app.route('/') def index(): return render_template('search.html')
@app.route('/test-page') def text(): return render_template('test.html')
@app.route('/search', methods=['GET']) def search(): # Get the 'query', 'limit', and 'offset' parameters from the request query = request.args.get('query', default='', type=str) limit = request.args.get('limit', default=10, type=int) offset = request.args.get('offset', default=0, type=int)
code# Call the query_database function with the provided parameters results = query_database(query, limit, offset) # Return the results as JSON return jsonify(results)if name == "main": app.run(debug=True)
- Assistant
The given code is a Flask application that provides a search functionality for a SQLite database. It has three routes:
- The '/' route displays the search.html template, which can be used to enter search queries and view the results.
- The '/test-page' route displays the test.html template.
- The '/search' route accepts GET requests and retrieves search parameters from the request. It then calls the query_database function with the provided parameters to fetch the results from the SQLite database. The results are then returned as a JSON response.
To add the information of interactions, IP, and user agent, you can modify the code as follows:
- Add an additional column for these details in the 'data' table of the 'leaks.db' database. For example, you can add columns named 'interaction', 'ip', and 'useragent'.