updated to output to json file
This commit is contained in:
parent
70d1999ca4
commit
d41f685f5c
Binary file not shown.
11
inex.py
11
inex.py
@ -5,6 +5,7 @@ from datetime import datetime
|
|||||||
from tomllib import load
|
from tomllib import load
|
||||||
import inexLogging
|
import inexLogging
|
||||||
import inexConnect
|
import inexConnect
|
||||||
|
from json import dump,dumps
|
||||||
|
|
||||||
class Inex:
|
class Inex:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -28,13 +29,19 @@ class Inex:
|
|||||||
self.dbUser = self.config["database"]["user"]
|
self.dbUser = self.config["database"]["user"]
|
||||||
self.dbPassword = self.config["database"]["password"]
|
self.dbPassword = self.config["database"]["password"]
|
||||||
self.dbQuery = self.config["database"]["query"]
|
self.dbQuery = self.config["database"]["query"]
|
||||||
|
self.outputFile = self.config["output"]["filename"]
|
||||||
|
|
||||||
# create the connection to the database
|
# create the connection to the database
|
||||||
self.cursor = self.ic.connectDatabase(self.db, self.dbDriver, self.dbServer, self.dbDatabase, self.dbUser, self.dbPassword)
|
self.cursor = self.ic.connectDatabase(self.db, self.dbDriver, self.dbServer, self.dbDatabase, self.dbUser, self.dbPassword)
|
||||||
|
|
||||||
self.query = self.ic.databaseQuery(self.cursor, self.dbQuery)
|
self.data = self.ic.databaseQuery(self.cursor, self.dbQuery)
|
||||||
|
|
||||||
print(self.query)
|
# self.jsonData = dumps(self.data)
|
||||||
|
# print(self.jsonData)
|
||||||
|
|
||||||
|
with open(self.outputFile, "w") as f:
|
||||||
|
dump(self.data, f)
|
||||||
|
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
if __name__== "__main__":
|
if __name__== "__main__":
|
||||||
|
@ -2,9 +2,12 @@ def connectDatabase(lib, driver, server, database, user, password):
|
|||||||
connectionString = f'DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={server};DATABASE={database};UID={user};PWD={password};TrustServerCertificate=yes'
|
connectionString = f'DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={server};DATABASE={database};UID={user};PWD={password};TrustServerCertificate=yes'
|
||||||
print(connectionString)
|
print(connectionString)
|
||||||
connection = lib.connect(connectionString)
|
connection = lib.connect(connectionString)
|
||||||
# connection = lib.connect(f'DRIVER={{driver}};SERVER={server};DATABASE={database}')
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
return cursor
|
return cursor
|
||||||
|
|
||||||
def databaseQuery(cursor, query):
|
def databaseQuery(cursor, query, args=(), one=False):
|
||||||
cursor.execute(query)
|
cur = cursor.execute(query, args)
|
||||||
|
r = [dict((cur.description[i][0], value) \
|
||||||
|
for i, value in enumerate(row)) for row in cur.fetchall()]
|
||||||
|
cur.connection.close()
|
||||||
|
return (r[0] if r else None) if one else r
|
Loading…
x
Reference in New Issue
Block a user