Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.4 kB
2
Indexable
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'
    __opId=''
    __buId=''
    __response = {}
    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
            output = []
            query = 'global rows;rows=hos_cart_details.objects().filter(hos_cart_details.hoscd_businessid=businessid).allow_filtering();'
            #exec(query)
            for row in rows:
                data = [{
                'hoscd_event_date': str(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
                }]
                output.append(data)

        if len(output) == 0:
            return (("200", []))

        gc_collect()
        return (("200", output))

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