Untitled
unknown
plain_text
3 years ago
6.0 kB
7
Indexable
from warnings import filterwarnings as warn_filterwarnings
warn_filterwarnings('ignore')
from models.hos_cart_details import hos_cart_details
from models.hos_cart_details_by_username import hos_cart_details_username
#from models.hos_cart_details_by_businessid import hos_cart_dtls_by_business
#from models.hos_cart_details_by_status import hos_cart_details_status
from configparser import ConfigParser as conf_ConfigParser
from config.logger import configlogfile
from json import loads as json_loads
from json import dumps as json_dumps
from gc import collect as gc_collect
from sys import exc_info as sys_exc_info
from datetime import datetime, timezone
from os import environ as os_environ
from os import path as os_path
from sys import path as sys_path
import pandas as pd
import ast
import json
import sys
import base64
from flask import Flask, jsonify
from flask import request
from flask import Response
def getData(args, configvalues): # UI Based Calling
logging = configlogfile()
__funcReturnAPICode = '0000'
__funcReturnDesc = 'Successfully Completed the Process'
eventdate = request.args.get('eventdate')
business_id = request.args.get('businessid')
username = request.args.get('username')
status= request.args.get('status')
startDate = request.args.get('startDate')
logging.info(("startDate : ",startDate))
logging.info(("startDate : ",type(startDate)))
endDate = request.args.get('endDate')
logging.info(("endDate : ",type(endDate)))
cartMapping = json_loads(configvalues.get('apiconfiguration', 'cartColumnMapping', raw=True))
try:
logging.info(("get cartDetails process started"))
validkeys = json_loads(configvalues.get('apiconfiguration', 'validkeys', raw=True))
logging.info(("Args.keys() : %s" % set(list(args.keys()))))
logging.info(("validkeys : %s" % set(validkeys)))
if 'businessid' in args.keys():
results = hos_cart_details.objects.filter(hoscd_businessid=business_id).allow_filtering()
elif 'eventdate' in args.keys():
results = hos_cart_details.objects.filter(hoscd_event_date=eventdate)
elif 'username' in args.keys():
results = hos_cart_details_username.objects.filter(hoscd_username=username)
elif 'status' in args.keys():
results = hos_cart_details.objects.filter(hoscd_status=status).allow_filtering()
elif 'businessid' in args.keys() and 'status' in args.keys():
results = hos_cart_details.objects.filter(hoscd_businessid=business_id,hoscd_status=status).allow_filtering()
elif 'startDate' in args.keys() and 'endDate' in args.keys():
#__lt and __gt are used to perform less than and greater than operation
results = hos_cart_details.objects.filter(hoscd_event_date__gt=startDate,hoscd_event_date__lt=endDate).allow_filtering()
#results = hos_cart_details.objects.filter(hoscd_event_date>startDate,hoscd_event_date<endDate).allow_filtering()
else:
return ((["9003"], "Invalid Arguments passed to the API."))
data = [{
cartMapping['hoscd_event_date']: str(r.hoscd_event_date),
cartMapping['hoscd_buid']: r.hoscd_buid,
cartMapping['hoscd_createdtime']: str(r.hoscd_createdtime),
cartMapping['hoscd_opid']: r.hoscd_opid,
cartMapping['hoscd_status']: r.hoscd_status,
cartMapping['hoscd_type']: r.hoscd_type,
cartMapping['hoscd_updatedtime']: str(r.hoscd_updatedtime),
cartMapping['hoscd_username']: r.hoscd_username,
cartMapping['hoscd_value']: base64.b64encode(r.hoscd_value).decode('utf-8'),
cartMapping['hoscd_valuetype']: r.hoscd_valuetype
} for r in results]
logging.debug(results)
logging.debug(data)
count = len(data)
return (("200", {"count":count,"data":data}))
except Exception as e:
gc_collect()
logging.error("Error - {} . Line No - {} ".format(str(e), str(sys.exc_info()[-1].tb_lineno)))
# return (("500", "Technical exception"))
return ((["9003"], "Error - {} . Line No - {} ".format(str(e), str(sys.exc_info()[-1].tb_lineno))))
above one is my api and below one is my model class
from flask_cqlalchemy import CQLAlchemy
import uuid
from datetime import datetime
db = CQLAlchemy()
def serializetojson(self):
results = {}
for key in self.keys():
if type(self[key]) in [str, int, bool, float, dict]:
results[key] = self[key]
elif type(self[key]) == type(None):
results[key] = None
elif type(self[key]) is list:
lst = []
for x in self[key]:
lst.append(x)
results[key] = lst
elif type(self[key]) in [uuid.UUID, datetime]:
results[key] = str(self[key])
elif type(self[key] == bytes):
results[key] = str(self[key].decode('utf-8'))
else:
results[key] = str(type(self[key]))
return results
class hos_cart_details_username(db.Model):
__keyspace__ = 'hobs_ods_staging'
hoscd_username=db.columns.Text(primary_key=True)
hoscd_event_date = db.columns.Date(primary_key=True)
hoscd_businessid = db.columns.Text(primary_key=True)
hoscd_key = db.columns.Text(primary_key=True)
hoscd_buid = db.columns.Text()
hoscd_createdtime = db.columns.DateTime()
hoscd_opid = db.columns.Text()
hoscd_status = db.columns.Text()
hoscd_type = db.columns.Text()
hoscd_updatedtime = db.columns.DateTime()
hoscd_value = db.columns.Blob()
hoscd_valuetype = db.columns.Text()
def __json__(self):
results = serializetojson(self)
return results
db.sync_table(hos_cart_details_username)
Editor is loading...