Refactor python files
This commit is contained in:
@ -30,6 +30,21 @@ def cast_value(value: str) -> Any:
|
||||
raise RuntimeError(f'unable to infer type of value "{value}"')
|
||||
|
||||
|
||||
def convert_value(value: Any, table: str = None, column: str = None) -> str:
|
||||
if value is None:
|
||||
return ''
|
||||
if type(value) == str:
|
||||
return f'"{value}"'
|
||||
elif type(value) == bool:
|
||||
return 'T' if value else 'F'
|
||||
elif type(value) == datetime.datetime and table is not None and column is not None:
|
||||
if value.year == 1899 and value.month == 12 and value.day == 30:
|
||||
return value.strftime('%H:%M:%S')
|
||||
elif value.hour == 0 and value.minute == 0 and value.second == 0:
|
||||
return value.strftime('%Y-%m-%d')
|
||||
return str(value)
|
||||
|
||||
|
||||
def parse_line(line_str: str) -> Iterator[str]:
|
||||
w = None
|
||||
s = False
|
||||
@ -70,15 +85,4 @@ def parse_dict(filename: str) -> Iterator[Dict[str, Any]]:
|
||||
|
||||
|
||||
def format_row(*values) -> str:
|
||||
row = ''
|
||||
for val in values:
|
||||
if val is None:
|
||||
pass
|
||||
elif type(val) == str:
|
||||
row += f'"{val}"'
|
||||
elif type(val) == bool:
|
||||
row += 'T' if val else 'F'
|
||||
else:
|
||||
row += str(val)
|
||||
row += ';'
|
||||
return f'{row[:-1]}\n'
|
||||
return ';'.join([convert_value(v) for v in values]) + '\n'
|
||||
|
Reference in New Issue
Block a user