Created
October 9, 2018 21:27
-
-
Save yozhsh/e5984e3a879d86d9fa23d4e8a345595f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_params(http_parameters: dict, client_identicator): | |
error = {"status": 400} | |
actions = { | |
'current': Sale.current_abones(client_identicator), | |
'previous': Sale.previous_abones(client_identicator), | |
'all': Sale.all_abones(client_identicator) | |
} | |
try: | |
abones_info = http_parameters['abones_info'] | |
if abones_info[0] == '': | |
return error | |
if abones_info[0][0] is '(' and abones_info[0][-1] is ')': | |
parameters_info = abones_info[0][1:] | |
params_without_brackets = parameters_info[:-1] | |
list_of_params = params_without_brackets.split(",") | |
print("LLIST OF PARAMS", list_of_params) | |
check_val = list_of_params[0] | |
try: | |
if isinstance(int(check_val), int): | |
return error | |
except ValueError: | |
try: | |
if isinstance(float(check_val), float): | |
return error | |
except ValueError: | |
pass | |
data = [] | |
for param in list_of_params: | |
if param in list(actions.keys()): | |
data.append({param.upper(): actions[param]}) | |
else: | |
for x in list(actions.keys()): | |
if x in re.findall(x, param): | |
data.append({x.upper(): actions[x]}) | |
return data | |
else: | |
return error | |
except KeyError: | |
#print("HTTP PARAMS", http_parameters) | |
return error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment