Untitled
unknown
plain_text
7 months ago
3.0 kB
1
Indexable
Never
from warnings import filterwarnings as warn_filterwarnings warn_filterwarnings('ignore') from models.hos_cart_details import hos_cart_details 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') 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).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))))