def process(event_id):
    #Initialize
    rows = None

    #Logging
    logging.basicConfig(
        filename=LOG_FILENAME,
        level=logging.DEBUG,
    )

    #Connect to database
    try:
        connTAB = mdb.connect(host, usrnm, psswrd, db_name)
        cursor = connTAB.cursor(mdb.cursors.DictCursor)
    except:
        logger.messageException("TABS  | Except in connecting to database")

    try:
        sql = "SELECT * from _events_tabs where id = '%s'" % (event_id)
        cursor.execute(sql)
        row = cursor.fetchone()
        connTAB.commit()

    except mdb.Error, e:

        connTAB.rollback()
        logger.messageException(
            str("TABS  | MySQLdb error %d: %s" % (e.args[0], e.args[1])))
Exemple #2
0
def send_thread():
    while True:
        #Sending messages
        try:
            time.sleep(0.005)
            sql = "SELECT * FROM `waterfall_2` WHERE processed = '0'"
            cursor2.execute((sql))
            rows = cursor2.fetchall()
            if len(rows) > 0:
                sql = "UPDATE `waterfall_2` SET processed = '1' WHERE processed = '0'"
                cursor2.execute((sql))
                bot.stdio_message('Waterfall succeeded!!!!')
                logger.messageInfo("Waterfall_0 ==> Message sent to telephone")
            connRAW2.commit()

        except:
            logger.messageException("Waterfall_0 ERROR selecting from DB")
def send_thread():			
    while True:
	#Sending messages
        try:
            time.sleep(0.005)
            sql="SELECT * FROM `waterfall_2` WHERE processed = '0'"
            cursor2.execute((sql))
            rows=cursor2.fetchall()
            if len(rows)>0:
                sql="UPDATE `waterfall_2` SET processed = '1' WHERE processed = '0'"  
                cursor2.execute((sql))
                bot.stdio_message('Waterfall succeeded!!!!')
                logger.messageInfo("Waterfall_0 ==> Message sent to telephone")
            connRAW2.commit() 
            
        except:
            logger.messageException("Waterfall_0 ERROR selecting from DB")
def receive_thread():
    global message
    #Receiving messages
    while True:
        (i , o, e) = select.select(socketlist.keys(),[],[],1)
        for each in i:
            if socketlist[each] == 'xmpp':
                cl.Process(1)
                if message !='':
                    logger.messageInfo("Message is:"+message+"--")
                    try:
                        sql="INSERT INTO `test_table` (naam) VALUES ('Waterfall')"
                        cursor.execute((sql))
                        logger.messageInfo("Waterfall_0 ==> New Event Created")
                        connRAW.commit()
                    except:
                        logger.messageException("Waterfall_0 ERROR inserting in DB")
                    message=''
            else:
                raise Exception("Unknown socket type: %s" % repr(socketlist[each]))
Exemple #5
0
def receive_thread():
    global message
    #Receiving messages
    while True:
        (i, o, e) = select.select(socketlist.keys(), [], [], 1)
        for each in i:
            if socketlist[each] == 'xmpp':
                cl.Process(1)
                if message != '':
                    logger.messageInfo("Message is:" + message + "--")
                    try:
                        sql = "INSERT INTO `test_table` (naam) VALUES ('Waterfall')"
                        cursor.execute((sql))
                        logger.messageInfo("Waterfall_0 ==> New Event Created")
                        connRAW.commit()
                    except:
                        logger.messageException(
                            "Waterfall_0 ERROR inserting in DB")
                    message = ''
            else:
                raise Exception("Unknown socket type: %s" %
                                repr(socketlist[each]))
Exemple #6
0
import logger  #this is the logger.py file

#Logging
logging.basicConfig(
    filename=LOG_FILENAME,
    level=logging.DEBUG,
)

message = ''

#Connect to database for thread 1
try:
    connRAW = mdb.connect(host, usrnm, psswrd, db_name)
    cursor = connRAW.cursor(mdb.cursors.DictCursor)
except:
    logger.messageException("RAW  | Except in connecting to database")

#Connect to database for thread 2
try:
    connRAW2 = mdb.connect(host, usrnm, psswrd, db_name)
    cursor2 = connRAW2.cursor(mdb.cursors.DictCursor)
except:
    logger.messageException("RAW  | Except in connecting to database")


class Bot:
    def __init__(self, jabber, remotejid):
        self.jabber = jabber
        self.remotejid = remotejid

    def register_handlers(self):
    try:
        sql = "SELECT * from _events_tabs where id = '%s'" % (event_id)
        cursor.execute(sql)
        row = cursor.fetchone()
        connTAB.commit()

    except mdb.Error, e:

        connTAB.rollback()
        logger.messageException(
            str("TABS  | MySQLdb error %d: %s" % (e.args[0], e.args[1])))

    except:
        connTAB.rollback()
        logger.messageException(
            "TABS  | Exception in reading from __events_tabs")

    try:

        logger.messageInfo("TABS  | new TABS event: " + str(row))

        id = row["id"]
        RAW_id = row["RAW_id"]
        timestamp = row["timestamp"]
        timestamp_delayed = timestamp + datetime.timedelta(0, 1)
        type_id = row["type_id"]
        user_id = row["user_id"]
        location_id = row["location_id"]
        tab_id = row["tab_id"]
        description = row[
            "description"]  #The "name:" variable stays in the description. It is useless to take it out.
		#Connect to database
		connRAW = mdb.connect(host, usrnm, psswrd, db_name);
		cursor = connRAW.cursor(mdb.cursors.DictCursor)

		#Check for newly uploaded ZIP files 
		list = os.listdir("/home/") # returns list
		list.sort()
		

		for file in list:
			try:
				unzip("/home/"+file, home+"/unzipped/")
				os.rename("/home/"+file, home+"/processed/"+file)
				logger.messageInfo(file+" successfully unzipped and moved to PROCESSED folder") 
			except:
				logger.messageException("Exception during Unzip - File is probably still being transferred")
			
			#remove test message from WebBox
			try:
				os.remove(home+"/unzipped/Info.xml")		
			except:
				pass
			
			
			
		#Removing LOG files (device events), keeping MEAN files (actual data)
		list = os.listdir(home+"/unzipped") # returns list
		list.sort()
		 
		for file in list:
			
#Initialize
time.sleep(10)  #to make sure MySQL has started up fully
rows = None

#Logging
logging.basicConfig(
    filename=LOG_FILENAME,
    level=logging.DEBUG,
)

#Connect to database
try:
    connRAW = mdb.connect(host, usrnm, psswrd, db_name)
    cursor = connRAW.cursor(mdb.cursors.DictCursor)
except:
    logger.messageException("RAW  | Except in connecting to database")

while True:
    #check for new events
    try:
        time.sleep(0.2)

        sql = "SELECT * from __events_RAW where processed = '0' ORDER BY id ASC"
        cursor.execute(sql)
        rows = cursor.fetchall()
        connRAW.commit()

    except mdb.Error, e:

        connRAW.rollback()
        logger.messageException(
import logger  #this is the logger.py file

#Logging
logging.basicConfig(
    filename=LOG_FILENAME,
    level=logging.DEBUG,
)

message = ''

#Connect to database
try:
    connRAW = mdb.connect(host, usrnm, psswrd, db_name)
    cursor = connRAW.cursor(mdb.cursors.DictCursor)
except:
    logger.messageException("RAW  | Except in connecting to database")

while True:
    time.sleep(0.005)
    try:
        sql = "SELECT * FROM `waterfall_1` WHERE processed = '0'"
        cursor.execute((sql))
        rows = cursor.fetchall()
        if len(rows) > 0:
            sql = "UPDATE `waterfall_1` SET processed = '1' WHERE processed = '0'"
            cursor.execute((sql))
            sql = "INSERT INTO `waterfall_2` (original_id) VALUES ('12345')"
            cursor.execute((sql))
            logger.messageInfo("Waterfall_2 ==> Event processed")
        connRAW.commit()
from datetime import datetime 
from variables import *
import logging
import logger	#this is the logger.py file

#Logging
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)

message = ''

#Connect to database
try:
	connRAW = mdb.connect(host, usrnm, psswrd, db_name);
	cursor = connRAW.cursor(mdb.cursors.DictCursor)
except:
	logger.messageException("RAW  | Except in connecting to database")


while True:
    time.sleep(0.005)
    try:
        sql="SELECT * FROM `test_table` WHERE processed = '0'"
        cursor.execute((sql))
        rows=cursor.fetchall()
        if len(rows)>0:
            sql="UPDATE `test_table` SET processed = '1' WHERE processed = '0'"  
            cursor.execute((sql))
            sql="INSERT INTO `waterfall_1` (original_id) VALUES ('12345')"
            cursor.execute((sql))
            logger.messageInfo("Waterfall_1 ==> Event processed")
        connRAW.commit()
        cursor = connRAW.cursor(mdb.cursors.DictCursor)

        #Check for newly uploaded ZIP files
        list = os.listdir("/home/")  # returns list
        list.sort()

        for file in list:
            try:
                unzip("/home/" + file, home + "/unzipped/")
                os.rename("/home/" + file, home + "/processed/" + file)
                logger.messageInfo(
                    file +
                    " successfully unzipped and moved to PROCESSED folder")
            except:
                logger.messageException(
                    "Exception during Unzip - File is probably still being transferred"
                )

            #remove test message from WebBox
            try:
                os.remove(home + "/unzipped/Info.xml")
            except:
                pass

        #Removing LOG files (device events), keeping MEAN files (actual data)
        list = os.listdir(home + "/unzipped")  # returns list
        list.sort()

        for file in list:

            if "Mean." in file and ".zip" in file:
from variables import *
import threading
import logging
import logger	#this is the logger.py file

#Logging
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)

message = ''

#Connect to database for thread 1
try:
	connRAW = mdb.connect(host, usrnm, psswrd, db_name);
	cursor = connRAW.cursor(mdb.cursors.DictCursor)
except:
	logger.messageException("RAW  | Except in connecting to database")

#Connect to database for thread 2
try:
	connRAW2 = mdb.connect(host, usrnm, psswrd, db_name);
	cursor2 = connRAW2.cursor(mdb.cursors.DictCursor)
except:
	logger.messageException("RAW  | Except in connecting to database")

	
	
	
class Bot:

    def __init__(self,jabber,remotejid):
        self.jabber = jabber
#Initialize
#time.sleep(10)			#to make sure MySQL has started up fully
timeout=1
rows=None 
naam='Frans van Hoogstraten'

#Logging
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)

#Connect to database
try:
	connRAW = mdb.connect(host, usrnm, psswrd, db_name);
	cursor = connRAW.cursor(mdb.cursors.DictCursor)
except:
	logger.messageException("RAW  | Except in connecting to database")
	
	

while True:
#	time.sleep(timeout)
	if naam=='Frans van Hoogstraten':
		naam='Jan van Meurs'
	else:
		naam='Frans van Hoogstraten'

	# write event
	try:
		
		sql="INSERT INTO `test_table` (`naam`) "+\
		"VALUES ('%s')" % (naam)
from datetime import datetime 
from variables import *

#Initialize
time.sleep(10)			#to make sure MySQL has started up fully
rows=None 

#Logging
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)

#Connect to database
try:
	connRAW = mdb.connect(host, usrnm, psswrd, db_name);
	cursor = connRAW.cursor(mdb.cursors.DictCursor)
except:
	logger.messageException("RAW  | Except in connecting to database")
	
	

while True:
	#check for new events
	try:
		time.sleep(0.2)
		
		sql="SELECT * from __events_RAW where processed = '0' ORDER BY id ASC"
		cursor.execute(sql)
		rows=cursor.fetchall()
		connRAW.commit()

	except mdb.Error, e:
	  
		logger.messageException("SALES | Except in connecting to database")
		
	try:
		sql="SELECT * from _events_sales where id = '%s'" % (event_id)
		cursor.execute(sql)
		row=cursor.fetchone()
		connSAL.commit()

	except mdb.Error, e:
	  
		connSAL.rollback()
		logger.messageException(str("SALES | MySQLdb error %d: %s" % (e.args[0],e.args[1])))

	except:
		connSAL.rollback()
		logger.messageException(str("SALES | Exception in reading from __events_sales"))

	try:
		rows=""			#in case the SELECT try-loop fails, 'rows' has been declared and is empty
		
		logger.messageInfo("SALES | new SALES event: " + str(row))

		id=row["id"]
		RAW_id=row["RAW_id"]
		timestamp=row["timestamp"]
		type_id=row["type_id"]
		tab_id=row["tab_id"]
		consumption_id=row["consumption_id"]
		consumption_nr=row["consumption_nr"]
		description=row["description"]
		amount=row["amount"]