sc | get_param 2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@staticmethod
def get_param(name, param_type='string', delimiter=',', default=None):
value = request.args.get(name, default)
if value is None:
return default
try:
if param_type == 'int':
value = int(float(value))
elif param_type == 'date':
value = value.strip()
value = parser.parse(value)
elif param_type == 'timestamp':
value = datetime.utcfromtimestamp(int(float(value)))
elif param_type == 'list':
values = []
for item in value.split(delimiter):
values.append(item.strip())
return values
elif param_type == 'list-int':
values = []
for item in value.split(delimiter):
try:
values.append(int(float(item.strip())))
except ValueError:
pass
return values
else:
value = value.strip()
return value