Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.3 kB
2
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 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


def getData(args, configvalues):  # UI Based Calling
    logging = configlogfile()
    __funcReturnAPICode = '0000'
    __funcReturnDesc = 'Successfully Completed the Process'
    eventdate = request.args.get('eventdate')
    businessid = request.args.get('businessid')
    username = request.args.get('username')
    output = []
    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():
            global rows
            rows=[]
            results = hos_cart_details.objects.filter(hoscd_businessid=businessid).allow_filtering()


            data = [{
                    'hoscd_event_date': r.hoscd_event_date,
                    'hoscd_buid': r.hoscd_buid,
                    'hoscd_createdtime': r.hoscd_createdtime,
                    'hoscd_opid': r.hoscd_opid,
                    'hoscd_status': r.hoscd_status,
                    'hoscd_type': r.hoscd_type,
                    'hoscd_updatedtime': r.hoscd_updatedtime,
                    'hoscd_username': r.hoscd_username,
                    'hoscd_value': base64.b64encode(r.hoscd_value).decode('utf-8'),
                    'hoscd_valuetype': r.hoscd_valuetype
                      }for r in results]
            count = results.count()
            return jsonify({'data': data, 'count': count})

        if 'eventdate' in args.keys():
            results = results = hos_cart_details.objects.filter(hoscd_event_date=eventdate).allow_filtering()

            data = [{
                    'hoscd_event_date': r.hoscd_event_date,
                    'hoscd_buid': r.hoscd_buid,
                    'hoscd_createdtime': r.hoscd_createdtime,
                    'hoscd_opid': r.hoscd_opid,
                    'hoscd_status': r.hoscd_status,
                    'hoscd_type': r.hoscd_type,
                    'hoscd_updatedtime': r.hoscd_updatedtime,
                    'hoscd_username': r.hoscd_username,
                    'hoscd_value': base64.b64encode(r.hoscd_value).decode('utf-8'),
                    'hoscd_valuetype': r.hoscd_valuetype
                      }for r in results]
            count = results.count()
            return jsonify({'data': data, 'count': count})




    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"))