Update csv handling

This commit is contained in:
2023-05-04 23:07:06 +02:00
parent 19b2bccae3
commit 3b7a28cc23
5 changed files with 183 additions and 193 deletions

View File

@ -11,7 +11,7 @@ import ctypes.wintypes
import hashlib
import pypyodbc
import csv
import utils
IGNORED_NAMES = ['Windows', 'Program Files', 'Program Files (x86)', 'AppData']
@ -138,11 +138,10 @@ def main() -> None:
cur.execute(f"SELECT * FROM {t_name} ORDER BY `{desc[0][0]}`;")
cols = [t[0] for t in cur.description]
with open(f'{args.output}/{t_name}.csv', 'wb+') as f:
f.write((';'.join(cols) + '\n').encode('utf-8'))
with utils.csv_open(f'{args.output}/{t_name}.csv') as f:
f.header(cols)
for row in cur:
values = [csv.convert_value(val, table=t_name, column=col) for col, val in zip(cols, row)]
f.write((';'.join(values) + '\n').encode('utf-8'))
f.row((utils.convert_value(val, table=t_name, column=col) for col, val in zip(cols, row)), raw=True)
print(f'Exported {t_name} successfully!', flush=True)
finally: