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
|
||||
import inexLogging
|
||||
import inexConnect
|
||||
from json import dump,dumps
|
||||
|
||||
class Inex:
|
||||
def __init__(self):
|
||||
@ -28,13 +29,19 @@ class Inex:
|
||||
self.dbUser = self.config["database"]["user"]
|
||||
self.dbPassword = self.config["database"]["password"]
|
||||
self.dbQuery = self.config["database"]["query"]
|
||||
self.outputFile = self.config["output"]["filename"]
|
||||
|
||||
# create the connection to the database
|
||||
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
|
||||
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'
|
||||
print(connectionString)
|
||||
connection = lib.connect(connectionString)
|
||||
# connection = lib.connect(f'DRIVER={{driver}};SERVER={server};DATABASE={database}')
|
||||
cursor = connection.cursor()
|
||||
return cursor
|
||||
|
||||
def databaseQuery(cursor, query):
|
||||
cursor.execute(query)
|
||||
def databaseQuery(cursor, query, args=(), one=False):
|
||||
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