Update wgexport
This commit is contained in:
@ -1,10 +1,10 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import datetime
|
||||||
|
import decimal
|
||||||
import pypyodbc
|
import pypyodbc
|
||||||
|
|
||||||
#pypyodbc.lowercase = False
|
|
||||||
|
|
||||||
|
|
||||||
def convert(a) -> str:
|
def convert(a) -> str:
|
||||||
if type(a) == str:
|
if type(a) == str:
|
||||||
@ -13,6 +13,13 @@ def convert(a) -> str:
|
|||||||
return "T" if a else "F"
|
return "T" if a else "F"
|
||||||
elif a is None:
|
elif a is None:
|
||||||
return ""
|
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:
|
else:
|
||||||
return str(a)
|
return str(a)
|
||||||
|
|
||||||
@ -22,10 +29,8 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('wgdaten')
|
parser.add_argument('wgdaten')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
conn = pypyodbc.connect(
|
pypyodbc.lowercase = False
|
||||||
r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};" +
|
conn = pypyodbc.connect(f"Driver={{Microsoft Access Driver (*.mdb, *.accdb)}};Dbq={args.wgdaten};")
|
||||||
f"Dbq={args.wgdaten};")
|
|
||||||
|
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -34,6 +39,7 @@ if __name__ == '__main__':
|
|||||||
for file, _, t_name, t_type, _ in tbls:
|
for file, _, t_name, t_type, _ in tbls:
|
||||||
print(t_name)
|
print(t_name)
|
||||||
cur.execute(f"SELECT * FROM {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]
|
cols = [t[0] for t in cur.description]
|
||||||
|
|
||||||
with open(f'tables/{t_name}.csv', 'wb+') as f:
|
with open(f'tables/{t_name}.csv', 'wb+') as f:
|
||||||
|
Reference in New Issue
Block a user