2023-05-26 10:29:20 +04:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
class RawData:
|
|
|
|
def __init__(self, data):
|
|
|
|
self.__dict__.update(data)
|
|
|
|
|
2023-05-26 11:22:38 +04:00
|
|
|
def get_str(self, attr):
|
|
|
|
return RawData.get_str_st(self.__dict__, attr)
|
|
|
|
|
2023-05-26 10:29:20 +04:00
|
|
|
@staticmethod
|
2023-05-26 11:22:38 +04:00
|
|
|
def get_str_st(value, attr):
|
2023-05-26 10:29:20 +04:00
|
|
|
if value is None:
|
|
|
|
return ''
|
2023-05-26 11:22:38 +04:00
|
|
|
result = value[attr]
|
|
|
|
if result is None:
|
|
|
|
return ''
|
|
|
|
return result
|
|
|
|
|
|
|
|
def get_int(self, attr):
|
|
|
|
return RawData.get_int_st(self.__dict__, attr)
|
2023-05-26 10:29:20 +04:00
|
|
|
|
|
|
|
@staticmethod
|
2023-05-26 11:22:38 +04:00
|
|
|
def get_int_st(value, attr):
|
2023-05-26 10:29:20 +04:00
|
|
|
if value is None:
|
|
|
|
return -1
|
2023-05-26 11:22:38 +04:00
|
|
|
result = value[attr]
|
|
|
|
if result is None:
|
|
|
|
return -1
|
|
|
|
if not str(result).isnumeric():
|
|
|
|
print(f'The value {result} is not a number')
|
|
|
|
return -1
|
|
|
|
return result
|
2023-05-26 10:29:20 +04:00
|
|
|
|
|
|
|
@staticmethod
|
2023-05-26 11:22:38 +04:00
|
|
|
def get_date_st(value):
|
2023-05-26 10:29:20 +04:00
|
|
|
if value is None:
|
2023-05-26 11:22:38 +04:00
|
|
|
return ''
|
2023-05-26 10:29:20 +04:00
|
|
|
try:
|
|
|
|
return datetime.strptime(value, '%d.%m.%Y').date()
|
|
|
|
except ValueError:
|
|
|
|
try:
|
|
|
|
return datetime.strptime(value, '%d.%m.%y').date()
|
|
|
|
except ValueError:
|
|
|
|
print(f'Invalid date {value}')
|
2023-05-26 11:22:38 +04:00
|
|
|
return ''
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_collection_st(collection, function):
|
|
|
|
return list(map(lambda item: function(item), [] if collection is None else collection))
|