Exemple #1
0
def delete_flower(listaFlowers, lista):
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()

        query = "DELETE FROM `Flowers` WHERE "
        print(query)
        for i in range(len(listaFlowers)):
            query2 = []
            for j in range(len(lista)):
                if (i == int(lista[j])):
                    print("usunieto ")
                    print(listaFlowers[i])
                    query2 = "Nazwa='" + listaFlowers[i][0]
                    query2 += "' AND ZLACZE='" + listaFlowers[i][1]
                    query2 += "' AND Pin='" + str(listaFlowers[i][2])
                    query2 += "' AND data_utw='" + str(listaFlowers[i][3])
                    query2 += "' AND Godzina_podl='" + str(listaFlowers[i][4])
                    query2 += "' AND data_podlewania='" + str(
                        listaFlowers[i][5])
                    query2 += "' AND okr_podl='" + str(
                        listaFlowers[i][6]) + "'"
                    s = str(query) + str(query2)
                    cursor.execute(s)
                    print(s)
        cnx.commit()
        cursor.close()
        cnx.close()
        return 2
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
def flower_add(id_u, name, device, pin, hh, mm, nexty):
    try:
        if (int(device) > 0):
            cnx = database_static.connecting()
            cursor = cnx.cursor()
            today = datetime.now().date()
            tomorrow = datetime.now().date() + timedelta(days=1)
            db = datetime.strptime(
                str(tomorrow) + " " + str(hh) + ":" + str(mm),
                '%Y-%m-%d %H:%M')
            db2 = datetime.strptime(str(hh) + ":" + str(mm), '%H:%M').time()
            dev2 = checkedDevice(int(device))
            add_user = (
                "INSERT INTO Flowers "
                "(id_u, Nazwa, Zlacze, Pin, data_utw, Godzina_podl, data_podlewania, okr_podl) "
                "VALUES (%s, %s, %s, %s, %s, %s, %s, %s)")

            data_employee = (str(id_u), name, dev2, str(pin), today, db2, db,
                             str(nexty))

            result = cursor.execute(add_user, data_employee)
            print(result)
            cnx.commit()
            cursor.close()
            cnx.close()
            return 2
        else:
            return 0

    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
def nawadnianie(listaFlowers, lista):
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()
        add_user = ("INSERT INTO `Irrigation` "
                    "(id_f, Nazwa, Zlacze, Pin, godz_wyk) "
                    "VALUES (%s, %s, %s, %s,%s)")
        a = datetime.now().time()
        sec = 0
        for i in range(len(listaFlowers)):
            for j in range(len(lista)):
                if (i == int(lista[j])):
                    b = addSecs(a, 600 + sec)
                    data_employee = (str(listaFlowers[i][0]),
                                     listaFlowers[i][1], listaFlowers[i][2],
                                     str(listaFlowers[i][3]), b)
                    result = cursor.execute(add_user, data_employee)
                    sec += 60

        cnx.commit()
        cursor.close()
        cnx.close()
        return 2
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
def returnTable():
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()

        query = "SELECT id_f, Nazwa, Zlacze, Pin,data_podlewania,okr_podl from `Flowers`"
        r = cursor.execute(query)
        result = cursor.fetchall()
        count = cursor.rowcount
        cursor.close()
        cnx.close()
        return result
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
Exemple #5
0
def returnMonth():
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()

        query = "SELECT DISTINCT MONTH(data_podlewania) FROM `History`"
        r = cursor.execute(query)
        months = []
        for month, in cursor:
            months.append(month)
        cursor.close()
        cnx.close()
        return months
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
Exemple #6
0
def returnTable(curMonth, curYear):
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()

        query = "SELECT f.nazwa,h.data_podlewania,h.data_nast_podl from `History` h JOIN `Flowers` f ON h.id_f=f.id_f WHERE MONTH(h.data_podlewania)=" + str(
            curMonth) + " AND YEAR(h.data_podlewania)=" + str(curYear)
        r = cursor.execute(query)
        result = cursor.fetchall()
        count = cursor.rowcount
        cursor.close()
        cnx.close()
        return result
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
Exemple #7
0
def returnYear():
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()

        query = "SELECT DISTINCT Year(data_podlewania) FROM `History`"
        r = cursor.execute(query)
        years = []
        for year, in cursor:
            years.append(year)
        cursor.close()
        cnx.close()
        return years
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
def checkFlowerName(name):
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()
        query = "SELECT Nazwa FROM `Flowers` WHERE Nazwa = '" + str(name) + "'"

        result = cursor.execute(query)
        for (name) in cursor:
            print("{}".format(name))
        count = cursor.rowcount
        count += 1
        cursor.close()
        cnx.close()
        return count
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return -1
Exemple #9
0
def checkUser(name):
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()
        
        query="SELECT Nazwa_User, mail, haslo, data_utw FROM `Users` WHERE Nazwa_User = '******'"
        
        result=cursor.execute(query)
        print(result)
        for (Nazwa_User, mail, haslo, data_utw) in cursor:
            print("{}, {}, {} was hired on {:%d %b %Y}".format(Nazwa_User, mail, haslo, data_utw))
        count = cursor.rowcount
        cursor.close()
        cnx.close()
        return count
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
def saveHistory(id_f, old_date, new_date):
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()
        add_user = ("INSERT INTO `History` "
                    "(id_f, data_podlewania, data_nast_podl) "
                    "VALUES (%s, %s, %s)")

        data_employee = (id_f, old_date, new_date)

        result = cursor.execute(add_user, data_employee)
        print(result)
        cnx.commit()
        cursor.close()
        cnx.close()
        return 2
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
def checkFlowerHours(hh, mm):
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()
        db = datetime.strptime(str(hh) + ":" + str(mm), "%H:%M").time()
        query = "SELECT Nazwa,Godzina_podl,data_podlewania FROM `Flowers` WHERE Godzina_podl = '" + str(
            db) + "'"
        result = cursor.execute(query)
        print(result)
        for (Nazwa, Zlacze, Pin) in cursor:
            print("{}, {}, {}".format(Nazwa, Zlacze, Pin))
        count = cursor.rowcount
        count += 1
        cursor.close()
        cnx.close()
        return count
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
def updateTable(id_f, name):
    try:
        print(id_f, name)
        cnx = database_static.connecting()
        cursor = cnx.cursor()
        query = "UPDATE `Flowers` SET data_podlewania=%s WHERE id_f=%s AND Nazwa=%s"
        today = datetime.now()
        b = today + timedelta(seconds=300)
        db = datetime.strptime(
            str(b.date()) + " " + str(b.hour) + ":" + str(b.minute),
            '%Y-%m-%d %H:%M')
        datetm = (db, id_f, name)
        r = cursor.execute(query, datetm)
        cnx.commit()
        cursor.close()
        cnx.close()
        return 2
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
Exemple #13
0
def singing(name,email,password):
    try:
        cnx = database_static.connecting()
        cursor = cnx.cursor()
        tomorrow = datetime.now().date()

        add_user = ("INSERT INTO Users "
                "(Nazwa_User, mail, haslo, data_utw) "
                "VALUES (%s, %s, %s, %s)")

        data_employee = (name, email, password ,tomorrow)

        cursor.execute(add_user, data_employee)
        cnx.commit()
        cursor.close()
        cnx.close()
        return 2
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0
def checkFlowerPin(pin, zlacze):
    try:
        print(zlacze)
        cnx = database_static.connecting()
        cursor = cnx.cursor()
        dev2 = checkedDevice(int(zlacze))
        query = "SELECT Nazwa, Zlacze, Pin FROM `Flowers` WHERE Zlacze = '" + dev2 + "'" + " AND Pin='" + str(
            pin) + "'"
        print(query)
        result = cursor.execute(query)
        for (Nazwa, Zlacze, Pin) in cursor:
            print("{}, {}, {}".format(Nazwa, Zlacze, Pin))
        count = cursor.rowcount
        count += 1
        cursor.close()
        cnx.close()
        return count
    except mysql.connector.Error as err:
        print("Something went wrong: {}".format(err))
        return 0