initial commit, configuration, connection
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
config.toml
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								__pycache__/inexConnect.cpython-312.pyc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								__pycache__/inexConnect.cpython-312.pyc
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								__pycache__/inexLogging.cpython-312.pyc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								__pycache__/inexLogging.cpython-312.pyc
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										10
									
								
								config.toml.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								config.toml.example
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										41
									
								
								inex.py
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										10
									
								
								inexConnect.py
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										0
									
								
								inexLogging.py
									
									
									
									
									
										Normal file
									
								
							
		Reference in New Issue
	
	Block a user