Пример #1
0
def addUserSession(email, password):
    conn = initializeLoginDB()
    c = conn.cursor()
    dataInsert = (str(email), str(password))
    sql = '''SELECT * FROM loginInfo WHERE screenName = ? AND password = ?'''
    row = c.execute(sql, dataInsert).fetchone()
    try:
        x = 1
        custID = row[0]
        while x == 1:
            sessKey = random.randint(10000, 10000000)
            x = checkForExistingSess(c, sessKey)
        sql = '''INSERT INTO loginSessions VALUES (?, ?, ?);'''
        dataInsert = (sessKey, custID, currTime())
        c.execute(sql, dataInsert)
        conn.commit()
        c.close()
        return sessKey
    except KeyError:
        c.close()
        addUserSession(email, password)
    except Exception:
        traceback.print_exc()
        c.close()
        return 0
Пример #2
0
def addItem(sessKey):
    try:
        conn = initializeDb(getCustIdFromSessKey(sessKey))
        r = request.data
        itemData = json.loads(r)
        print(itemData)
        try:
            itemData = itemData["message"]
        except Exception:
            traceback.print_exc()
        print(itemData)
        uId = itemData['uId']
        itemNumber = itemData['itemNumber']
        initTime = currTime()
        creatorId = 0
        lifeTime = getLifetime(conn, int(itemNumber))
        x = addLabelToTable(conn, uId, itemNumber, lifeTime, initTime,
                            creatorId)
        if x:
            print('success')
        else:
            print('failure')
        return 'success'
    except Exception:
        traceback.print_exc()
        return 'error'
Пример #3
0
 def getLifeRemaining(self):
     lifeRemaining = (self.initTime + self.lifetime * 60 - currTime())
     return lifeRemaining
Пример #4
0
 def getLifeRemaining(self):
     lifeRemaining = ((60 * self.lifetime) - int(currTime() -
                                                 (self.initTime))) / 60
     return lifeRemaining
Пример #5
0
def runInterface(empIdNo=0, custIdNumber=0):

    custNo = custIdNumber
    if not custNo:
        custNo = login()
    conn = initializeDb(custNo)
    c = conn.cursor()
    c.execute("PRAGMA busy_timeout = 10000")
    c.close()

    empId = empIdNo

    if not empId:
        empId = input("What is your ID number? ")
    else:
        pass

    pathSelector = input(
        "1: Add Item, 2: Delete Item, 3: View Item, 4: View All Items, 5: View All Items Of Type 6: Admin, 7: Exit "
    )

    if pathSelector == 1:
        name = raw_input("Food Type? ")
        name = name.lower()
        try:
            itemNumber = int(findItemNumber(conn, name))
            itemLife = int(getLifetime(conn, itemNumber))
            uId = input("Label Number?")
            time = currTime()
            x = addLabelToTable(conn, uId, itemNumber, itemLife, time, empId)
            if not x:
                print("Failure")
            else:
                print("Item Added")
        except Exception:
            print("Food type not in database. Add food type from Admin menu.")

    if pathSelector == 2:
        labelNo = input("Enter label number to delete: ")
        delLabelFromTable(conn, labelNo)

    if pathSelector == 3:
        try:
            labelNo = input("Enter label number to view: ")
            label = selLabelFromTable(conn, labelNo)
            label.printLabel(conn)
        except Exception:
            print("Label Number Not In Database")

    if pathSelector == 4:
        printAllLables(conn)

    if pathSelector == 5:
        name = raw_input("Food Type? ")
        name = name.lower()
        try:
            itemNumber = int(findItemNumber(conn, name))
        except Exception:
            print("Food type not in database. Add food type from Admin menu.")
        printAllLablesOfType(conn, itemNumber)

    if pathSelector == 6:
        pathSelector = input(
            "1: Add New Food Type, 2: Delete Food Type, 3: List All Food Types 4: Add Employee, 5: Remove Employee, 5: Back "
        )
        if pathSelector == 1:
            name = raw_input("Food Type? ")
            name = name.lower()
            itemLife = 0
            itemLife += 720 * input(
                "Enter number of months for which this item can be kept: ")
            itemLife += 24 * input(
                "Enter number of days for which this item can be kept: ")
            itemLife += input(
                "Enter number of hours for which this item can be kept: ")
            print(itemLife)
            itemLife = int(itemLife)
            x = item(name, getNewItemNumber(conn), itemLife)
            itemId = x.itemNumber
            addItemToTable(conn, itemId, name, itemLife)

        if pathSelector == 2:
            stringArg = raw_input(
                "Enter the name of the food type you would like to delete: ")
            stringArg = stringArg.lower()
            itemNum = findItemNumber(conn, stringArg)
            delItemFromTable(conn, itemNum)

        if pathSelector == 3:
            printAllItems(conn)

        if pathSelector == 4:
            pass
        if pathSelector == 5:
            pass

    if pathSelector == 7:
        custNo = 0
    runInterfaceRec(empId, custNo)