initial commit, configuration, connection

This commit is contained in:
Jonathan Branan 2024-06-24 16:28:51 -05:00
parent e44cb12fa9
commit 70d1999ca4
7 changed files with 62 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.toml

Binary file not shown.

Binary file not shown.

10
config.toml.example Normal file
View File

@ -0,0 +1,10 @@
[database]
driver = "ODBC Driver 18 for SQL Server"
server = "192.168.x.x"
database = "EFTDB"
user = "a"
password = "a"
query = "SELECT [Id],[Version] FROM [EFTDB].[dbo].[tbl_Schema_Version]"
[logging]
use_log = true

41
inex.py Normal file
View File

@ -0,0 +1,41 @@
import pandas
import pyodbc
import os
from datetime import datetime
from tomllib import load
import inexLogging
import inexConnect
class Inex:
def __init__(self):
"""Initilize config, calls functions from inex-connect.py and inex-logging.py"""
if os.path.exists('./config.toml'):
config_file_path = './config.toml'
with open(config_file_path, 'rb') as c:
self.config = load(c)
# assign libraries
self.pd = pandas
self.db = pyodbc
self.tm = datetime
self.il = inexLogging
self.ic = inexConnect
# set config
self.dbDriver = self.config["database"]["driver"]
self.dbServer = self.config["database"]["server"]
self.dbDatabase = self.config["database"]["database"]
self.dbUser = self.config["database"]["user"]
self.dbPassword = self.config["database"]["password"]
self.dbQuery = self.config["database"]["query"]
# 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)
print(self.query)
# Run
if __name__== "__main__":
Inex()

10
inexConnect.py Normal file
View File

@ -0,0 +1,10 @@
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)

0
inexLogging.py Normal file
View File