Updated json encoder to change sql unsupported object types to supported versions
This commit is contained in:
parent
d41f685f5c
commit
dbb5ca2b3b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
config.toml
|
config.toml
|
||||||
|
*.json
|
17
inex.py
17
inex.py
@ -1,11 +1,12 @@
|
|||||||
import pandas
|
import pandas
|
||||||
import pyodbc
|
import pyodbc
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
import datetime
|
||||||
from tomllib import load
|
from tomllib import load
|
||||||
import inexLogging
|
import inexLogging
|
||||||
import inexConnect
|
import inexConnect
|
||||||
from json import dump,dumps
|
import json
|
||||||
|
import decimal
|
||||||
|
|
||||||
class Inex:
|
class Inex:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -36,12 +37,18 @@ class Inex:
|
|||||||
|
|
||||||
self.data = self.ic.databaseQuery(self.cursor, self.dbQuery)
|
self.data = self.ic.databaseQuery(self.cursor, self.dbQuery)
|
||||||
|
|
||||||
# self.jsonData = dumps(self.data)
|
# print(self.data)
|
||||||
# print(self.jsonData)
|
|
||||||
|
|
||||||
with open(self.outputFile, "w") as f:
|
with open(self.outputFile, "w") as f:
|
||||||
dump(self.data, f)
|
json.dump(self.data, f, cls=Encoder)
|
||||||
|
|
||||||
|
class Encoder(json.JSONEncoder):
|
||||||
|
def default(self, o):
|
||||||
|
if isinstance(o, decimal.Decimal):
|
||||||
|
return int(o)
|
||||||
|
if isinstance(o, datetime.datetime):
|
||||||
|
return str(o)
|
||||||
|
return super().default(o)
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
if __name__== "__main__":
|
if __name__== "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user