Skip to content

Instantly share code, notes, and snippets.

@yozhsh
Created October 9, 2018 21:27
Show Gist options
  • Save yozhsh/e5984e3a879d86d9fa23d4e8a345595f to your computer and use it in GitHub Desktop.
Save yozhsh/e5984e3a879d86d9fa23d4e8a345595f to your computer and use it in GitHub Desktop.
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