From 5f5d652e4e4edc34f8ea1aebe660d48cec2182be Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Tue, 15 Nov 2022 11:27:10 +0100 Subject: [PATCH] Update wgexport --- wgmaster/wgexport.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/wgmaster/wgexport.py b/wgmaster/wgexport.py index 7852605..9ce862d 100644 --- a/wgmaster/wgexport.py +++ b/wgmaster/wgexport.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- import argparse +import datetime +import decimal import pypyodbc -#pypyodbc.lowercase = False - def convert(a) -> str: if type(a) == str: @@ -13,6 +13,13 @@ def convert(a) -> str: return "T" if a else "F" elif a is None: return "" + elif type(a) == datetime.datetime: + if a.year == 1899 and a.month == 12 and a.day == 30: + return a.strftime('%H:%M:%S') + elif a.hour == 0 and a.minute == 0 and a.second == 0: + return a.strftime('%Y-%m-%d') + else: + return str(a) else: return str(a) @@ -22,10 +29,8 @@ if __name__ == '__main__': parser.add_argument('wgdaten') args = parser.parse_args() - conn = pypyodbc.connect( - r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};" + - f"Dbq={args.wgdaten};") - + pypyodbc.lowercase = False + conn = pypyodbc.connect(f"Driver={{Microsoft Access Driver (*.mdb, *.accdb)}};Dbq={args.wgdaten};") cur = conn.cursor() try: @@ -34,6 +39,7 @@ if __name__ == '__main__': for file, _, t_name, t_type, _ in tbls: print(t_name) cur.execute(f"SELECT * FROM {t_name};") + print([(t[0], t[1]) for t in cur.description]) cols = [t[0] for t in cur.description] with open(f'tables/{t_name}.csv', 'wb+') as f: