Untitled
unknown
plain_text
6 months ago
1.4 kB
3
Indexable
Never
from flask import Flask, request, jsonify from cassandra.cluster import Cluster from models import HosCartDetails app = Flask(__name__) @app.route('/hoscd_event_date', methods=['GET']) def get_hoscd_event_date(): # Get the date parameter from the request URL date_param = request.args.get('date') # Connect to the Cassandra cluster cluster = Cluster(['127.0.0.1']) session = cluster.connect('hobs_ods_staging') # Query the hos_cart_details table for the given date query = HosCartDetails.objects.filter(hoscd_event_date=date_param).allow_filtering() result = session.execute(query._select_query()) # Format the results as a JSON response response = [] for row in result: response.append({ 'hoscd_event_date': str(row.hoscd_event_date), 'hoscd_businessid': row.hoscd_businessid, 'hoscd_key': row.hoscd_key, 'hoscd_buid': row.hoscd_buid, 'hoscd_createdtime': str(row.hoscd_createdtime), 'hoscd_opid': row.hoscd_opid, 'hoscd_status': row.hoscd_status, 'hoscd_type': row.hoscd_type, 'hoscd_updatedtime': str(row.hoscd_updatedtime), 'hoscd_username': row.hoscd_username, 'hoscd_value': str(row.hoscd_value), 'hoscd_valuetype': row.hoscd_valuetype }) return jsonify(response)