32 lines
797 B
Python
32 lines
797 B
Python
|
from datetime import datetime
|
||
|
|
||
|
|
||
|
class RawData:
|
||
|
def __init__(self, data):
|
||
|
self.__dict__.update(data)
|
||
|
|
||
|
@staticmethod
|
||
|
def get_str(value, attr):
|
||
|
if value is None:
|
||
|
return ''
|
||
|
return '' if value is None else value[attr]
|
||
|
|
||
|
@staticmethod
|
||
|
def get_int(value, attr):
|
||
|
if value is None:
|
||
|
return -1
|
||
|
return -1 if value is None else value[attr]
|
||
|
|
||
|
@staticmethod
|
||
|
def get_date(value):
|
||
|
if value is None:
|
||
|
return None
|
||
|
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}')
|
||
|
return None
|