Esempio n. 1
0
def createResponseMessage(message):
    loggingConfig = python_config.read_logging_config()
    enabled = loggingConfig.get('enabled')
    api = loggingConfig.get('api')
    auth = loggingConfig.get('auth')
    domain = loggingConfig.get('domain')

    loggingNotEnabledMsg = "logging is not enabled in the config.ini."

    messageBase = Eby_Message.MessageBase(message)

    response = None

    isKeepAliveMessage = messageBase.CheckIfMessageIsKeepAlive()

    if isKeepAliveMessage:
        response = messageBase.getFullAcknowledgeKeepAliveMessage()
        return response
    #if not, then it's a data message
    else:
        messageBase.getMessageType(
        )  #save the message data to the database, log it, etc.
        response = messageBase.getFullAcknowledgeKeepAliveMessage()
        if enabled == "1":
            hostLog.log(auth, domain, "WXS to Host", "ACKNOWLE", response)
        else:
            print(loggingNotEnabledMsg)
        return response
Esempio n. 2
0
    def updateOrderComplete(self, connection):
        config = python_config.read_db_config()

        host = config.get('host')
        user = config.get('user')
        database = config.get('database')
        password = config.get('password')

        try:
            connection = mysql.connector.connect(host=host,
                                                 user=user,
                                                 database=database,
                                                 password=password)

            cursor = connection.cursor()

            updateOrderCompleteSQL = ("UPDATE dat_master SET "
                                      "o_comp = %s, "
                                      "updated_at = %s "
                                      "WHERE route_no = %s "
                                      "AND stop_no = %s")

            # currentTimeStamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            currentTimeStamp = datetime.now().strftime(
                '%Y-%m-%d %H:%M:%S.%f')[:-3]

            updateOrderValues = (1, currentTimeStamp, self.Route, self.Stop)

            cursor.execute(updateOrderCompleteSQL, updateOrderValues)
            connection.commit()
            rowcount = cursor.rowcount
            print("Rows updated: " + str(rowcount))

            cursor.close()
            connection.close()
            if rowcount > 0:
                return True
            else:
                return False
        except Exception as e:
            print(e)
            exc_type, exc_value, exc_traceback = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)
            exceptionMsg = exc_value
            exceptionDetails = ''.join('!! ' + line for line in lines)

            GlobalFunctions.logExceptionStackTrace(exceptionMsg,
                                                   exceptionDetails)
            hostLog.dbLog("Eby_OrderComplete", "Upd Err",
                          self.AsciiRequestMessage)
            return False

        finally:
            cursor.close()
            connection.close()
Esempio n. 3
0
def logExceptionStackTrace(exceptionMsg, exceptionDetails):
    loggingConfig = python_config.read_logging_config()

    enabled = loggingConfig.get('enabled')

    auth = loggingConfig.get('auth')
    domain = loggingConfig.get('domain')

    if enabled == "1":
        hostLog.log(auth, domain, "Socket Listener", "Exception",
                    exceptionMsg + " StackTrace: " + exceptionDetails)
    else:
        print("Exception", exceptionMsg + " StackTrace: " + exceptionDetails)
    def removeUnneededAssignments(self, connection):
        config = python_config.read_db_config()

        host = config.get('host')
        user = config.get('user')
        database = config.get('database')
        password = config.get('password')

        try:
            connection = mysql.connector.connect(host=host,
                                                 user=user,
                                                 database=database,
                                                 password=password)

            cursor = connection.cursor()

            deleteAssignmentSQL = ("DELETE FROM dat_master "
                                   "WHERE assignment_id = %s "
                                   "AND  c_comp = 0")

            deleteAssignmentValues = (self.AssignmentID, )

            cursor.execute(deleteAssignmentSQL, deleteAssignmentValues)
            connection.commit()

            cursor.close()
            connection.close()

        except Exception as e:
            print(e)
            exc_type, exc_value, exc_traceback = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)
            exceptionMsg = exc_value
            exceptionDetails = ''.join('!! ' + line for line in lines)

            GlobalFunctions.logExceptionStackTrace(exceptionMsg,
                                                   exceptionDetails)
            hostLog.dbLog("Eby_AssignmentComplete", "Upd Err",
                          self.AsciiRequestMessage)
            return False

        finally:
            cursor.close()
            connection.close()
Esempio n. 5
0
    def getDatMasterByContainerId(self, containerId):
        config = python_config.read_db_config()

        host = config.get('host')
        user = config.get('user')
        database = config.get('database')
        password = config.get('password')

        try:
            connection = mysql.connector.connect(host=host,
                                                 user=user,
                                                 database=database,
                                                 password=password)

            cursor = connection.cursor()

            getByContainerIdSQL = "SELECT * FROM dat_master WHERE container_id = %s"

            selectData = (containerId, )

            cursor.execute(getByContainerIdSQL, selectData)

            result = cursor.fetchone()

            cursor.close()
            connection.close()
            return result
        except Exception as e:
            print(e)
            #connection.rollback()
            exc_type, exc_value, exc_traceback = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)
            exceptionMsg = exc_value
            exceptionDetails = ''.join('!! ' + line for line in lines)

            GlobalFunctions.logExceptionStackTrace(exceptionMsg,
                                                   exceptionDetails)
            hostLog.dbLog("Eby_ContainerComplete", "Upd Err",
                          self.AsciiRequestMessage)
        finally:
            cursor.close()
            connection.close()
Esempio n. 6
0
    def getMasterRecordByAssignmentId(self):
        config = python_config.read_db_config()

        host = config.get('host')
        user = config.get('user')
        database = config.get('database')
        password = config.get('password')

        try:
            connection = mysql.connector.connect(
                host= host, 
                user= user, 
                database= database, 
                password= password 
            )

            cursor = connection.cursor(buffered=True)

            #getByContainerIdSQL = "SELECT * FROM dat_master WHERE container_id = %s" 
            sql = "SELECT date FROM assignment.dat_master WHERE assignment_id=" + "'" + str(self.AssignmentID) + "'"

            #selectData = (self.ContainerID,)

            cursor.execute(sql)
            
            result = cursor.fetchone()
            
            cursor.close()
            connection.close()
            return result
        except Exception as e:
            print(e)
            #connection.rollback()
            exc_type, exc_value, exc_traceback = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
            exceptionMsg = exc_value
            exceptionDetails = ''.join('!! ' + line for line in lines)
        
            GlobalFunctions.logExceptionStackTrace(exceptionMsg, exceptionDetails)
            hostLog.dbLog("Eby_NewContainer", "Upd Err", self.AsciiRequestMessage)          
        finally:
            cursor.close()
            connection.close()
Esempio n. 7
0
    def updateContainerAsComplete(self, connection):
        config = python_config.read_db_config()

        host = config.get('host')
        user = config.get('user')
        database = config.get('database')
        password = config.get('password')

        try:
            connection = mysql.connector.connect(host=host,
                                                 user=user,
                                                 database=database,
                                                 password=password)

            cursor = connection.cursor()

            updateContainerSQL = ("UPDATE dat_master SET "
                                  "c_comp = %s, "
                                  "carton_qty = %s, "
                                  "qc_flag = %s, "
                                  "updated_at = %s "
                                  "WHERE container_id = %s ")

            #currentTimeStamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            currentTimeStamp = datetime.now().strftime(
                '%Y-%m-%d %H:%M:%S.%f')[:-3]

            updateContainerValues = (1, self.CigaretteQuantity,
                                     int(self.QCFlag), currentTimeStamp,
                                     self.ContainerID)

            cursor.execute(updateContainerSQL, updateContainerValues)
            connection.commit()
            rowcount = cursor.rowcount
            print("Rows updated: " + str(rowcount))

            #Web-72
            datMaster = self.getDatMasterByContainerId(self.ContainerID)
            pickCode = datMaster[6][:3]
            if pickCode == "001":
                Eby_Jurisdiction_Processor.process(self.ContainerID)

            cursor.close()
            connection.close()
            if rowcount > 0:
                return True
            else:
                return False
        except Exception as e:
            print(e)
            exc_type, exc_value, exc_traceback = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)
            exceptionMsg = exc_value
            exceptionDetails = ''.join('!! ' + line for line in lines)

            GlobalFunctions.logExceptionStackTrace(exceptionMsg,
                                                   exceptionDetails)
            hostLog.dbLog("Eby_ContainerComplete", "Upd Err",
                          self.AsciiRequestMessage)
            return False

        finally:
            cursor.close()
            connection.close()
Esempio n. 8
0
from queue import Queue
import atexit

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:

    loggingConfig = python_config.read_logging_config()
    auth = loggingConfig.get('auth')
    domain = loggingConfig.get('domain')
    api = loggingConfig.get("api")
    url = domain + api

    serverParams = python_config.read_server_config()
    host = serverParams.get('host')
    port = int(serverParams.get('port'))
    print('Listening on HOST: ' + str(host) + ' and PORT: ' + str(port))
    hostLog.log(auth, domain, "WXS Info", "Socket Listen",
                'Listening on HOST: ' + str(host) + ' and PORT: ' + str(port))

    s.bind((host, port))
    s.listen()
    conn, addr = s.accept()
    data = b''
    with conn:
        print("Connected by", addr)
        hostLog.log(auth, domain, "WXS Info", "Socket Conn",
                    "Connected from " + str(addr))
        while True:
            try:

                chunk = conn.recv(1024)
                #data = conn.recv(1024)
Esempio n. 9
0
    def saveNewContainer(self):
        loggingConfig = python_config.read_logging_config()
        enabled = loggingConfig.get('enabled')
        auth = loggingConfig.get('auth')
        domain = loggingConfig.get('domain')

        existingRecord = self.doesNewContainerAlreadyExist()

        if existingRecord is not None:
            if enabled == "1":                                                              #the ContainerID
                hostLog.log(auth, domain, "HOST to WXS", "Dupl", existingRecord[2])
            return

        config = python_config.read_db_config()

        host = config.get('host')
        user = config.get('user')
        database = config.get('database')
        password = config.get('password')


        date = None
        assignmentRecords = self.getMasterRecordByAssignmentId()
        if assignmentRecords is not None and len(assignmentRecords) > 0:
            date = assignmentRecords[0]
                

            # (rjw 2020-11-14 11:47) -- needed to add in assignment date based on original date of assignment drop in case this ADDCONTA comes after midnight
            # date = "SELECT date FROM assignment.dat_master WHERE assignment_id=" + "'" + str(self.AssignmentID) + "'"
            # cursor.execute(date)
            # date = str(cursor.fetchone()[0])

            #print(date)

        try:
            connection = mysql.connector.connect(
                host= host, 
                user= user, 
                database= database, 
                password= password 
            )

            cursor = connection.cursor()

            addNewContainerSQL = ("INSERT INTO dat_master "
                                "(record_id, container_id, assignment_id, route_no, stop_no, pick_code, pick_type, jurisdiction, carton_qty, c_comp, a_comp, o_comp, r_comp, assign_name, status, date, created_at, updated_at) "
                                "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
            
            currentTimeStamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]

          
            
            newContainer = (
                self.MessageID, self.ContainerID, self.AssignmentID, self.RouteNumber, self.StopNumber, self.PickArea, self.PickType, self.Jurisdiction, self.NumberCartons, 0, 0, 0, 0, 'SOCKET', 'Pending', date, currentTimeStamp, currentTimeStamp
            )

            cursor.execute(addNewContainerSQL, newContainer)
            connection.commit()
            rowcount = cursor.rowcount
            print("Rows inserted: " + str(rowcount))

            cursor.close()
            connection.close()
            return True
        except Exception as e:
            print(e)
            #connection.rollback()         
            exc_type, exc_value, exc_traceback = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
            exceptionMsg = exc_value
            exceptionDetails = ''.join('!! ' + line for line in lines)
        
            GlobalFunctions.logExceptionStackTrace(exceptionMsg, exceptionDetails)
            hostLog.dbLog("Eby_NewContainer", "Upd Err", self.AsciiRequestMessage)
            return False
        
        finally:
            cursor.close()
            connection.close()