Beispiel #1
0
    def test_connection_to_db(self):
        db_con = DbConnection()

        # if connect() function call raises exception unit test fails
        cursor = db_con.connect()
        # is right instance and not null
        self.assertIsInstance(cursor, pymssql.Cursor)
Beispiel #2
0
def main():
    logger = Logger('coin_application', 'coins.log',
                    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    db = DbConnection('localhost', 6379, logger.logger)

    BitcoinCrawler(60, logger.logger,
                   'https://api.coinmarketcap.com/v1/ticker/bitcoin/', 10, db)
Beispiel #3
0
 def __init__(self, csvFilePath, clearTableFunction, insertRowFunction):
     super(FillTempTable, self).__init__()
     self.csvFilePath = csvFilePath
     self.clearTableFunction = clearTableFunction
     self.insertRowFunction = insertRowFunction
     conn = DbConnection().connection
     self.dbCore = Levy_Db(conn, None)
     self.lock = threading.Lock()
Beispiel #4
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        # Изображение
        self.pixmap = QPixmap('./uploads/tutorial3.jpg')
        # Если картинки нет, то QPixmap будет пустым,
        # а исключения не будет
        # self.image = QLabel(self)

        self.image.setPixmap(self.pixmap)

        self.gridLayout_2.addWidget(self.image, 4, 0, 1, 1)

        self.good_education = QLabel(self.info)
        self.good_education.setMaximumSize(QSize(16777215, 50))
        self.good_education.setStyleSheet(
            "font-size: 25px; font-weight: 900;\n")
        self.good_education.setAlignment(Qt.AlignCenter)
        self.good_education.setObjectName("good_education")
        self.gridLayout_2.addWidget(self.good_education, 5, 0, 1, 1)
        self.good_education.setText("Удачного обучения!")
        self.setWindowTitle("Ansheapable")
        self.load_mp3('uploads/super_angry.mp3')
        # making constants
        make_constants(self)
        self.json = TableWithJson('./parsing/user_info.json')
        self.json.read_file()
        self.create_piechart()
        self.reset_table()
        # widgets which are common for the choose panel
        self.choose_area = [
            self.choose_hard_russian, self.choose_long_english,
            self.choose_basic_english, self.choose_basic_russian,
            self.choose_title, self.choose_long_russian, self.choose_numbers
        ]
        # widgets which are common for the writing field
        self.tr_area = [
            self.tr_back_label, self.tr_english_layout, self.tr_info_panel,
            self.tr_russian_layout, self.tr_back_label, self.tr_text_field,
            self.tr_writing_area, self.tr_title, self.tr_first_letter,
            self.tr_come_back
        ]

        self.rez_area = [
            self.rez_title, self.rez_mistakes, self.rez_main_text,
            self.rez_new_game, self.rez_empty_filler
        ]
        self.tr_come_back.clicked.connect(self.come_back)
        self.rez_new_game.clicked.connect(self.to_main_window)
        self.hide_elements(self.tr_area)
        self.hide_elements(self.rez_area)
        # add click listener to our buttons
        for item in self.choose_area:
            obj_type = type(item)
            if obj_type == QPushButton:
                item.clicked.connect(self.open_writin_panel)

        self.db_eventor = DbConnection('./parsing/db.sqlite')
Beispiel #5
0
    def test_config_parser(self):
        db_con = DbConnection()
        db_con.read_config()
        config = db_con.get_config()

        #config is of the right type
        self.assertIsInstance(config.get('AzureDB', 'server_URI'), str)
        self.assertIsInstance(config.get('AzureDB', 'username'), str)
        self.assertIsInstance(config.get('AzureDB', 'password'), str)
        self.assertIsInstance(config.get('AzureDB', 'database_1'), str)

        # config is not empty
        self.assertTrue(len(config.get('AzureDB', 'server_URI')) > 0)
        self.assertTrue(len(config.get('AzureDB', 'username')) > 0)
        self.assertTrue(len(config.get('AzureDB', 'password')) > 0)
        self.assertTrue(len(config.get('AzureDB', 'database_1')) > 0)
def sendStatusEmail(venueUid, eventUid, manual=False):
    """
        Sends an email for the given event to everyone on the email list of the given
        venue.
            1. Builds the email html body
            2. gathers the email addresses
            3. sends emails

        Parameters
        __________
        venueUid : int the venue_uid to send status emails for
        evenutUid : int the event_uid to send status emails for

        Reutrns
        _______
        out : boolean True if successful
    """

    from db_connection import DbConnection
    conn = DbConnection().connection

    statusRows = getStatusRows(conn, venueUid)

    body = '<font face="verdana">'

    table = getTable(statusRows)

    body += getIntro(conn, venueUid, eventUid)

    summary, totalTablets, badTablets = getSummary(statusRows)
    body += summary

    body += table

    if (manual):
        body += "<h1><b>*</b></h1>"

    subject = getSubject(totalTablets, badTablets)

    emailList = getEmailList(conn, venueUid)

    for email in emailList:
        gmail.sendGmail("*****@*****.**", "fkTUfbmv2YVy",
                        "*****@*****.**", email[0], subject,
                        body, 'Please, enable html to view this report')

    return True
from TrainingEventDB import TrainingEventDB
import HipChat
from config import CheckMateConfig
import redis

checkmateconfig = CheckMateConfig()
host = checkmateconfig.REDIS_ORDERS_HOST
port = checkmateconfig.REDIS_ORDERS_PORT
db = checkmateconfig.REDIS_ORDERS_DB
password = checkmateconfig.REDIS_ORDERS_PASSWORD
redisInstance = redis.Redis(host, port, db, password)

for key in redisInstance.keys('*:orders_by*'):
    redisInstance.delete(key)

conn = DbConnection().connection
dbCore = TrainingEventDB(conn)

trainingEvents = dbCore.getTrainingEvents()

HipChat.sendMessage("Moving " + str(len(trainingEvents)) + " training events", "Training", 447878, "purple")

for eventUid, venueUid in trainingEvents:

    print "Event UID: " + str(eventUid) + "  Venue UID: " + str(venueUid)
    
    #move the event to today
    dbCore.moveEventToToday(eventUid)

    #clear the orders
    dbCore.clearEventOrders(eventUid)
 def __init__(self, levyDB):
     self.db = DbConnection().connection
     self.levyDB = levyDB
Beispiel #9
0
import sqlalchemy as db
from sqlalchemy import Sequence

from db_connection import DbConnection

dbConnection = DbConnection()


class Kronikarz(dbConnection.Model):
    __tablename__ = 'kronikarz'
    nr_indeksu = db.Column('nr_indeksu', db.String(6), primary_key=True)
    imie = db.Column('imie', db.String(15))
    nazwisko = db.Column('nazwisko', db.String(20))
    email = db.Column('email', db.String(35))
    haslo = db.Column('haslo', db.String(15))
    uczelnia = db.Column('uczelnia', db.String(40))
    wydzial = db.Column('wydzial', db.String(40))
    kierunek = db.Column('kierunek', db.String(40))
    rodzaj = db.Column('rodzaj', db.String(40))

    def __init__(self, nr_indeksu, imie, nazwisko, email, haslo, uczlenia,
                 wydzial, kierunek, rodzaj):
        self.nr_indeksu = nr_indeksu
        self.imie = imie
        self.nazwisko = nazwisko
        self.email = email
        self.haslo = haslo
        self.uczlenia = uczlenia
        self.wydzial = wydzial
        self.kierunek = kierunek
        self.rodzaj = rodzaj
 def __get_db_cursor(self):
     self.__db_cursor = DbConnection().connect()
Beispiel #11
0
def sendEmail(allAppliedActions):

    print "Preparing Integration Email"

    #convert the uuid keyed dict of actions into a list of actions (we don't care about the uuids anymore
    #    tempActions = []
    #    for action in allAppliedActions:
    #        tempActions.append(allAppliedActions[action])
    #
    #    allAppliedActions = tempActions

    appliedActions = allAppliedActions

    conn = DbConnection().connection
    emailerDb = EmailerDb(conn)

    venueUids = emailerDb.getVenueUids()
    print "VENUE UIDS: " + str(venueUids)
    for venueUid in venueUids:
        venueUid = venueUid[
            0]  #DON'T FORGET python will return single values from mysql as an array with only one item
        appliedActions = getVenueAppliedActions(allAppliedActions, venueUid)
        print "Starting email for venue " + str(venueUid)
        print str(appliedActions)

        venueName = emailerDb.getVenueName(venueUid)

        sendEmail = False

        if len(appliedActions) > 0:
            sendEmail = True
            emailBody = "<html>Daily Integration has been completed for, " + venueName + ".  The following changes have been applied:"

            #EMPLOYEES:
            employeeActions = getAppliedActionsByType(appliedActions, "setup",
                                                      "employees")
            if len(employeeActions) > 0:
                emailBody += "<h3>EMPLOYEES:</h4>"

                addEmployeeActions = getInsertActions(employeeActions)
                if len(addEmployeeActions) > 0:
                    emailBody += "     New Employees:<ul>"
                    for addAction in addEmployeeActions:
                        levyTempPointerUid = addAction[0][13]
                        emailBody += getNewEmployeeLine(
                            emailerDb, levyTempPointerUid)
                    emailBody += "</ul>"

                editEmployeeActions = getUpdateActions(employeeActions)
                if len(editEmployeeActions) > 0:
                    emailBody += "Updated Employees:<ul>"
                    for editAction in editEmployeeActions:
                        emailBody += getUpdatedEmployeeLine(
                            emailerDb, editAction)
                    emailBody += "</ul>"
            #CUSTOMERS
            customerActions = getAppliedActionsByType(appliedActions,
                                                      "patrons", "patrons")
            suiteAssignmentActions = getAppliedActionsByType(
                appliedActions, "info", "unit_x_patrons")

            if len(customerActions) + len(suiteAssignmentActions) > 0:
                sendEmail = True
                emailBody += "<h3>CUSTOMERS:</h3>"

                addCustomerActions = getInsertActions(customerActions)
                if len(addCustomerActions) > 0:
                    emailBody += "New Customers:<ul>"
                    for addAction in addCustomerActions:
                        levyTempPointerUid = addAction[0][13]
                        emailBody += getNewCustomerLine(
                            emailerDb, levyTempPointerUid)
                    emailBody += "</ul>"

                editCustomerActions = getUpdateActions(customerActions)
                if len(editCustomerActions) > 0:
                    emailBody += "Updated Customers:<ul>"
                    for editAction in editCustomerActions:
                        emailBody += getUpdatedCustomerLine(
                            emailerDb, editAction)
                    emailBody += "</ul>"

                addSuiteAssignmentActions = getInsertActions(
                    suiteAssignmentActions)
                if len(addSuiteAssignmentActions) > 0:
                    emailBody += "Suite Assignments:<ul>"
                    for addAction in addSuiteAssignmentActions:
                        emailBody += getNewSuiteAssignmentLine(
                            emailerDb, addAction)
                    emailBody += "</ul>"

                deactivateSuiteAssignments = getDeactivateActions(
                    suiteAssignmentActions)
                print "Deactivate: " + str(deactivateSuiteAssignments)
                if len(deactivateSuiteAssignments) > 0:
                    emailBody += "Suite Deassignments:<ul>"
                    for deactivateAction in deactivateSuiteAssignments:
                        emailBody += getDeactivateSuiteAssignmentLine(
                            emailerDb, deactivateAction)
                    emailBody += "</ul>"

            #EVENTS
            eventActions = getAppliedActionsByType(appliedActions, "setup",
                                                   "events")
            if len(eventActions) > 0:
                sendEmail = True
                emailBody += "<h3>EVENTS:</h3>"

                addEventActions = getInsertActions(eventActions)
                if len(addEventActions) > 0:
                    emailBody += "New Events: <ul>"
                    for addAction in addEventActions:
                        levyTempPointerUid = addAction[0][13]
                        emailBody += getNewEventLine(emailerDb,
                                                     levyTempPointerUid)
                    emailBody += "</ul>"

            eventXVenuesActions = getAppliedActionsByType(
                appliedActions, "setup", "events_x_venues")
            updateEventXVenuesActions = getUpdateActions(eventXVenuesActions)
            updateEventActions = getUpdateActions(eventActions)
            updateAllEventActions = eventXVenuesActions + updateEventActions

            if len(updateAllEventActions) > 0:
                sendEmail = True
                emailBody += "UpdatedEvents:<ul>"
                for updateAction in updateAllEventActions:
                    emailBody += getUpdatedEventLine(emailerDb, updateAction)
                emailBody += "</ul>"

            #ITEMS
            updateItems = False
            itemActions = getAppliedActionsByType(appliedActions, "menus",
                                                  "menu_items")
            if len(itemActions) > 0:
                sendEmail = True
                emailBody += "<h3>ITEMS:</h3>"

                addItemActions = getInsertActions(itemActions)
                if len(addItemActions) > 0:
                    emailBody += "New Items:<ul>"
                    for addAction in addItemActions:
                        levyTempPointerUid = addAction[0][13]
                        emailBody += getNewItemLine(emailerDb,
                                                    levyTempPointerUid)
                    emailBody += "</ul>"

                updateMenuItemActions = getUpdateActions(itemActions)

                if len(updateMenuItemActions) > 0:
                    updateItems = True
                    emailBody += "Updated Items:<ul>"
                    for updateAction in updateMenuItemActions:
                        emailBody += getUpdatedMenuItemLine(
                            emailerDb, updateAction)

            menuXMenuActions = getAppliedActionsByType(appliedActions, "menus",
                                                       "menu_x_menu_items")
            updateMenuXMenuItemActions = getUpdateActions(menuXMenuActions)
            if len(updateMenuXMenuItemActions) > 0:
                sendEmail = True
                if updateItems == False:
                    updateItems = True
                    emailBody += "Updated Items:<ul>"
                for updateAction in updateMenuXMenuItemActions:
                    emailBody += getUpdatedMenuXMenuItemLine(
                        emailerDb, updateAction)

            if updateItems == True:
                emailBody += "</ul>"

            #SUITES
            unitActions = getAppliedActionsByType(appliedActions, "setup",
                                                  "units")
            if len(unitActions) > 0:
                sendEmail = True
                emailBody += "<h3>UNITS:</h3>"

                addUnitActions = getInsertActions(unitActions)
                if len(addUnitActions) > 0:
                    emailBody += "New Units:<ul>"
                    for addAction in addUnitActions:
                        levyTempPointerUid = addAction[0][13]
                        emailBody += getNewUnitLine(emailerDb,
                                                    levyTempPointerUid)
                    emailBody += "</ul>"
                editUnitActions = getUpdateActions(unitActions)
                if len(editUnitActions) > 0:
                    emailBody += "Updated Units:<ul>"
                    for editAction in editUnitActions:
                        emailBody += getUpdatedUnitLine(emailerDb, editAction)
                    emailBody += "</ul>"

                else:
                    print "NO UNIT UPDATES WERE MADE"
            emailBody += "</html>"

            print str(venueUid) + " OUTPUT: " + emailBody

            if sendEmail:
                emailAddresses = emailerDb.getEmailAddresses(venueUid)
                for address in emailAddresses:
                    address = address[0]
                    #gmail.sendGmail("*****@*****.**", "fkTUfbmv2YVy", "*****@*****.**", address, 'Integration Complete', emailBody, 'please open this in an HTML compatable email client')
                    MailGun.sendEmail("*****@*****.**", address,
                                      "Integration Complete", emailBody)
            else:
                print "Don't send email, nothing to tell the venue about"
        else:
            print "No actions were applied, Canceling Email"
Beispiel #12
0
                print(f'Received document snapshot (DEVICE): {doc.id}. Pump: {p_state} Lamp: {l_state} Heater: {h_state}')
                sensor_data_uploader.set_updated(False)


    spi = spidev.SpiDev()
    spi.open(0, 0)
    spi.max_speed_hz = 1000000
    GPIO.setmode(GPIO.BOARD)
    GPIO.setwarnings(False)
    # LED Azul de Prendido
    GPIO.setup(38, GPIO.OUT, initial=1)

    min_max_per_plant = json.load(codecs.open('min_max.json', 'r', 'utf-8-sig'))
    cred = './credentials.json'
    firebase_admin.initialize_app(credentials.Certificate(cred))
    conn = DbConnection(db_name='local.db')
    fsm = FirestoreManager(cred=cred, col_name='crops')
    mnt = FirestoreManager(cred=cred, col_name='monitor')
    mnt.retrieve_doc(doc_id='plant')

    power_sensor = PowerSupplySensor(pin=36, conn=conn)
    image_processor = ImageProcessor(conn=conn)
    photo_sensor = PhotoSensor(spi=spi, conn=conn, lamp_pin=22, pin=0)
    humidity_sensor = HumiditySensor(spi=spi, conn=conn, pump_pin=18, pin=1)
    temperature_sensor = TemperatureSensor(conn=conn, heater_pin=11, pin=22)
    sensor_data_uploader = SensorDataUploader(conn=conn, fsm=fsm)

    query_watch = None
    species = None

    while True: