Example #1
0
def guests_page():
    """
    guests()
    Shows a list of all the guests recorded in the hotel's database that match the parameter selected in the mainpage.
    Allows the receptionist to view and modify the informations about any guest: this is useful to update the database.
    Includes also the informations about all the reservations made by every guest. TO DO!!
    """
    if not session.get('logged_in'):
        abort(401)
    guests = set([])
    mappa = {}
    n = 0
    if request.method == "GET":
        for field in ["name", "surname", "phone", "passport", "email"]:
            if request.args.get(field):
                n = n + 1
                mappa[field] = request.args.get(field)
                matching = set(
                    get_item("guests", field, request.args.get(field)))
                if n == 1:
                    guests = matching
                else:
                    guests = guests.intersection(matching)
        if len(guests) == 0:
            mappa["msg"] = "Nessun ospite corrisponde ai criteri di ricerca."
            mappa["error"] = "TRUE"

    if request.method == "POST":
        lista = []
        for field in [
                "id_guest", "name", "surname", "passport", "email", "phone",
                "address", "info"
        ]:
            lista.append(request.form[field])
        modify_database("guest", "id_guest", id_guest, lista)
        mappa["msg"] = "Database aggiornato correttamente"
        #Regenerate guest's list
        for field in [
                "name", "surname", "phone", "passport", "address", "email"
        ]:
            if request.form[field]:
                n = n + 1
                mappa[field] = request.form[field]
                matching = set(get_item("guests", field, request.form[field]))
                if n == 1:
                    guests = matching
                else:
                    guests = guests.intersection(matching)
        if len(guests) == 0:
            mappa[
                "msg"] = "An error occured while saving the new guest's data. Please retry."
            mappa["error"] = "TRUE"

    mappa["guest"] = list(guests)

    print mappa
    template = env.get_template("guest.html")
    return template.render(mappa)
Example #2
0
def new_reserv_page():
    """
    new_reserv_page():
    This functions perform the actual booking process. If new_guest is set to TRUE, it also write a new entry in the guest's table to record the new user.
    This function returns many reservationIDs as the number of rooms booked and show them to the receptionist.
    It also sends a mail to the guest's email address with the reservation details.
    """
    if not session.get('logged_in'):
        abort(401)
    template = env.get_template("confirm.html")
    mappa = {}
    values = []

    for item in [
            "id_guest", "name", "surname", "email", "passport", "phone",
            "address", "info"
    ]:
        values.append(request.form[item])
    mappa["guest"] = values
    print 1
    if request.form["new_guest"]:
        result = add_to_db("guests", values)
        if result != "OK":
            mappa[
                "msg"] = "An error occured while recording the new guest's data into the database. No reservations made yet. Please retry and be sure that the guest's data inserted are correct."
            mappa["error"] = "TRUE"
            return template.render(mappa)
    print 2
    ids = []
    for room in id_rooms():
        print room[0]
        values[0] = n_items("reservations", "", "") + 1  #The new ID
        ids.append(values[0])
        print 4
        if request.form.get(room[0]):
            print 5
            for item in ["id_guest", "id_room", "checkin", "checkout"]:
                values.append(request.form[item])
                result = add_to_db("reservations", values)
                print "ADDED"
                if result != "OK":
                    mappa[
                        "msg"] = "An error occured while creating the new reservation. Please check what's recorded in the system, in order to spot mistakes in the database's content."
                    mappa["error"] = "TRUE"
    print 3
    mappa["id"] = ids
    for i in ids:
        id_room = get_item("reservations", "id_res", i)[1]
        days = get_item("reservations", "id_res", i)[4] - get_item(
            "reservations", "id_res", i)[3]
        tot = tot + get_item("rooms", "id_room", id_room)[3] * days
    mappa["price"] = tot

    return template.render(mappa)
Example #3
0
def guests_page():
    """
    guests()
    Shows a list of all the guests recorded in the hotel's database that match the parameter selected in the mainpage.
    Allows the receptionist to view and modify the informations about any guest: this is useful to update the database.
    Includes also the informations about all the reservations made by every guest. TO DO!!
    """
    if not session.get('logged_in'):
        abort(401)
    guests = set([])
    mappa = {}
    n = 0
    if request.method == "GET":
        for field in ["name", "surname", "phone", "passport", "email"]:
            if request.args.get(field):
                n = n + 1
                mappa[field] = request.args.get(field)
                matching = set(get_item("guests", field, request.args.get(field)))
                if n == 1:
                    guests = matching
                else:
                    guests = guests.intersection(matching)
        if len(guests) == 0:
            mappa["msg"] = "Nessun ospite corrisponde ai criteri di ricerca."
            mappa["error"] = "TRUE"

    if request.method == "POST":
        lista = []
        for field in ["id_guest", "name", "surname", "passport", "email", "phone", "address", "info"]:
            lista.append(request.form[field])
        modify_database("guest", "id_guest", id_guest, lista)
        mappa["msg"] = "Database aggiornato correttamente"
        #Regenerate guest's list
        for field in ["name", "surname", "phone", "passport", "address", "email"]:
            if request.form[field]:
                n = n + 1
                mappa[field] = request.form[field]
                matching = set(get_item("guests", field, request.form[field]))
                if n == 1:
                    guests = matching
                else:
                    guests = guests.intersection(matching)
        if len(guests) == 0:
            mappa["msg"] = "An error occured while saving the new guest's data. Please retry."
            mappa["error"] = "TRUE"
                    
    mappa["guest"] = list(guests)

    print mappa
    template = env.get_template("guest.html")
    return template.render(mappa)
Example #4
0
def new_reserv_page():
    """
    new_reserv_page():
    This functions perform the actual booking process. If new_guest is set to TRUE, it also write a new entry in the guest's table to record the new user.
    This function returns many reservationIDs as the number of rooms booked and show them to the receptionist.
    It also sends a mail to the guest's email address with the reservation details.
    """
    if not session.get('logged_in'):
        abort(401)
    template = env.get_template("confirm.html")
    mappa = {}
    values = []
    
    for item in ["id_guest", "name", "surname", "email", "passport", "phone", "address", "info"]:
        values.append(request.form[item])
    mappa["guest"] = values
    print 1
    if request.form["new_guest"]:
        result = add_to_db("guests", values)
        if result != "OK":
            mappa["msg"]="An error occured while recording the new guest's data into the database. No reservations made yet. Please retry and be sure that the guest's data inserted are correct."
            mappa["error"]="TRUE"
            return template.render(mappa)
    print 2
    ids = []
    for room in id_rooms():
        print room[0]
        values[0] = n_items("reservations", "", "") + 1         #The new ID
        ids.append(values[0])
        print 4
        if request.form.get(room[0]):
            print 5
            for item in ["id_guest", "id_room", "checkin", "checkout"]:
                values.append(request.form[item])
                result = add_to_db("reservations", values)
                print "ADDED"
                if result != "OK":
                    mappa["msg"]="An error occured while creating the new reservation. Please check what's recorded in the system, in order to spot mistakes in the database's content."
                    mappa["error"]="TRUE"
    print 3
    mappa["id"] = ids
    for i in ids:
        id_room = get_item("reservations", "id_res", i)[1]
        days = get_item("reservations", "id_res", i)[4] - get_item("reservations", "id_res", i)[3]
        tot = tot + get_item("rooms", "id_room", id_room)[3]*days
    mappa["price"] = tot
            

    return template.render(mappa)
Example #5
0
    def get_item_id(self):
        ''' Get synced item from embydb.
        '''
        item = database.get_item(self.kodi_id, self.media)

        if not item:
            return

        return {
            'Id': item[0],
            'UserData': json.loads(item[4]) if item[4] else {},
            'Type': item[3]
        }
def on_play(data, server):
    ''' Setup progress for jellyfin playback.
    '''
    player = xbmc.Player()

    try:
        kodi_id = None

        if player.isPlayingVideo():
            ''' Seems to misbehave when playback is not terminated prior to playing new content.
                The kodi id remains that of the previous title. Maybe onPlay happens before
                this information is updated. Added a failsafe further below.
            '''
            item = player.getVideoInfoTag()
            kodi_id = item.getDbId()
            media = item.getMediaType()

        if kodi_id is None or int(
                kodi_id) == -1 or 'item' in data and 'id' in data[
                    'item'] and data['item']['id'] != kodi_id:

            item = data['item']
            kodi_id = item['id']
            media = item['type']

        LOG.info(" [ play ] kodi_id: %s media: %s", kodi_id, media)

    except (KeyError, TypeError):
        LOG.debug("Invalid playstate update")

        return

    if settings('useDirectPaths') == '1' or media == 'song':
        item = database.get_item(kodi_id, media)

        if item:

            try:
                file = player.getPlayingFile()
            except Exception as error:
                LOG.exception(error)

                return

            item = server.jellyfin.get_item(item[0])
            item['PlaybackInfo'] = {'Path': file}
            playutils.set_properties(
                item, 'DirectStream'
                if settings('useDirectPaths') == '0' else 'DirectPlay')
def matching_guest(keys, values):
    """
    This function tries to find a guest in the database, given some parameters different from the ID.
    Returns a list of guests that match in the values given in "keys".
    The two lists MUST have the same lenght.
    """
    n = 0
    match = []
    for n in xrange(len(keys)):
        dblista = get_item("guests", keys[n], values[n])
        #        print "    dblista " + keys[n] + ": " + values[n]
        if n == 0:
            match = set(dblista)
        match = match.intersection(set(dblista))
    return list(match)
def matching_guest(keys, values):
    """
    This function tries to find a guest in the database, given some parameters different from the ID.
    Returns a list of guests that match in the values given in "keys".
    The two lists MUST have the same lenght.
    """
    n = 0
    match=[]
    for n in xrange(len(keys)):
        dblista = get_item("guests", keys[n], values[n])
#        print "    dblista " + keys[n] + ": " + values[n]
        if n == 0:
            match = set(dblista)
        match = match.intersection(set(dblista))
    return list(match)
Example #9
0
    def VideoLibrary_OnUpdate(self, server, data, *args, **kwargs):
        ''' Safe to replace in child class.
            Only for manually marking as watched/unwatched
        '''
        reset_resume = False

        try:
            kodi_id = data['item']['id']
            media = data['item']['type']
            playcount = int(data.get('playcount', 0))
            LOG.info(" [ update/%s ] kodi_id: %s media: %s", playcount,
                     kodi_id, media)
        except (KeyError, TypeError):

            if 'id' in data and 'type' in data and window(
                    'emby.context.resetresume.bool'):

                window('emby.context.resetresume', clear=True)
                kodi_id = data['id']
                media = data['type']
                playcount = 0
                reset_resume = True
                LOG.info("reset position detected [ %s/%s ]", kodi_id, media)
            else:
                LOG.debug("Invalid playstate update")

                return

        item = database.get_item(kodi_id, media)

        if item:

            if reset_resume:
                checksum = item[4]
                server['api'].item_played(item[0], False)

                if checksum:
                    checksum = json.loads(checksum)
                    if checksum['Played']:
                        server['api'].item_played(item[0], True)
            else:
                if not window('emby.skip.%s.bool' % item[0]):
                    server['api'].item_played(item[0], playcount)

                window('emby.skip.%s' % item[0], clear=True)
Example #10
0
def buy_item(vendId):
  global dispenser_serial, phone_sock

  row = database.get_item(vendId)
  if not row:
    raise BadItem()
  price, quantity, name, cat = row
  if quantity < 1:
    raise SoldOut()

  account_manager.withdraw(price, "Vending machine purchase: " + name)
  
  if account_manager.account_type > AccountManager.TEST:
    database.vend_item(vendId)

  # vend the item
  print "Dispensing item " + vendId
  if dispenser_serial:
    dispenser_serial.write("I" + vendId)
def on_update(data, server):
    ''' Only for manually marking as watched/unwatched
    '''
    try:
        kodi_id = data['item']['id']
        media = data['item']['type']
        playcount = int(data['playcount'])
        LOG.info(" [ update/%s ] kodi_id: %s media: %s", playcount, kodi_id,
                 media)
    except (KeyError, TypeError):
        LOG.debug("Invalid playstate update")

        return

    item = database.get_item(kodi_id, media)

    if item:

        if not window('jellyfin.skip.%s.bool' % item[0]):
            server.jellyfin.item_played(item[0], playcount)

        window('jellyfin.skip.%s' % item[0], clear=True)
Example #12
0
    def show(self):
        import database as db

        print('Take a look in your character...\n')
        print('Name:', self.name)
        print('Level:', self.level)
        print('Exp:', self.exp)
        print('Class:', db.get_class(self.id_class).name)
        print('Race:', db.get_race(self.id_race).name)
        print(
            'Life:', self.life, '+ (',
            db.get_item(self.item_equipped).con /
            2 if self.item_equipped != 0 else '0', ')')
        print(
            'Mana:', self.mana, '+ (',
            db.get_item(self.item_equipped).int /
            2 if self.item_equipped != 0 else '0', ')')
        print(
            'Con:', self.con, '+ (',
            db.get_item(self.item_equipped).con
            if self.item_equipped != 0 else '0', ')')
        print(
            'Str:', self.str, '+ (',
            db.get_item(self.item_equipped).str
            if self.item_equipped != 0 else '0', ')')
        print(
            'Int:', self.int, '+ (',
            db.get_item(self.item_equipped).int
            if self.item_equipped != 0 else '0', ')')
        print(
            'Spd:', self.spd, '+ (',
            db.get_item(self.item_equipped).spd
            if self.item_equipped != 0 else '0', ')')
        print(
            'Item:',
            db.get_item(self.item_equipped).name
            if self.item_equipped != 0 else 'none')
Example #13
0
page_list_class = 'pager'
page_item_class = 'pager__item'

# HTML parsing
page_html = BeautifulSoup(br.open(messages_url).read(), "html.parser")
page_items_html = page_html.find('ul', {'class': page_list_class}).find_all('li', {'class': page_item_class})

for page_element in enumerate(page_items_html[:-2]):  # Remove 'volgende' and 'last' from the page items
    page_html = BeautifulSoup(br.open(messages_url + '?page=' + str(page_element[0])).read(), "html.parser")
    messages_h2 = page_html.find('div', {'class': messages_class}).find_all('h2')
    messages_date_div = page_html.find_all('div', {'class': messages_date_class})

    for messages_h2_index, message_h2_element in enumerate(messages_h2):
        if message_h2_element.a is not None:
            message_url = message_prefix_url + message_h2_element.a.get('href')
            if database.get_item(message_url) is None:
                message_html = BeautifulSoup(br.open(message_url).read(), "html.parser")
                message_publish_date = str(messages_date_div[messages_h2_index].find('div').find('div').text)[1:-1]
                try:
                    message_description = message_html.find(
                        'div', {'class': message_description_class}).find_all(
                        'div', {'class': message_description_item_class})
                except AttributeError:
                    message_description = []
                message_author = message_html.find('div', {'class': message_author_class}).a.text
                message_attachments = message_html.find('div', {'class': message_attachments_class})
                message_need_to_knows = message_html.find('div', {'class': message_ntk_class})
                message_categories = message_html.find('div', {'class': message_category_class})

                title = message_h2_element.a.text
                description = ''
Example #14
0
    def fight(self, enemy):

        player = self
        initial_life = self.life
        round = 0
        while enemy.life > 0 and player.life > 0:

            os.system('cls')
            round += 1
            print('Round: ' + str(round))
            print(player.name + ' - ' + str(player.life) + ' X ' +
                  str(enemy.life) + ' - ' + enemy.name)
            t.sleep(1)

            #player turn
            dice = r.randint(1, 20)
            #print(player.name+' roll: '+str(dice))
            if dice + player.str / 5 >= enemy.con + db.get_item(
                    enemy.item_equipped
            ).con if enemy.item_equipped != 0 else enemy.con:
                totalHit = player.str + r.randint(1, 4) + db.get_item(
                    player.item_equipped
                ).str if player.item_equipped != 0 else player.str + r.randint(
                    1, 4)
                print(player.name + ' hit: ' + str(totalHit))
                enemy.life -= totalHit
            else:
                print(player.name + ' miss the attack!')
            t.sleep(1)
            if enemy.life <= 0: break
            #enemy turn
            dice = r.randint(1, 20)
            #print(enemy.name+' roll: '+str(dice))
            if dice + enemy.str / 5 >= player.con + db.get_item(
                    player.item_equipped
            ).con if player.item_equipped != 0 else player.con:
                totalHit = enemy.str + r.randint(1, 4) + db.get_item(
                    enemy.item_equipped
                ).str if enemy.item_equipped != 0 else enemy.str + r.randint(
                    1, 4)
                print(enemy.name + ' hit: ' + str(totalHit))
                player.life -= totalHit
            else:
                print(enemy.name + ' miss the attack!')
            if player.life <= 0: break
            t.sleep(1.5)

        print()
        if (player.life > 0):
            # you win
            print(player.name + ' have defeated ' + enemy.name)
            print('You got ' + str(enemy.exp) + ' exp!')
            self.exp += enemy.exp
            if (enemy.item_equipped != 0):
                item = db.get_item(enemy.item_equipped)
                db.att_item(self, item)
                print('You drop the ' + item.name)
            self.life = initial_life
            db.update_player(self)
            t.sleep(3)
            return True

        else:
            print(enemy.name + ' have killed you!')
            self.life = initial_life
            t.sleep(3)
            return False
Example #15
0
def reserv_page():
    """
    reserv()
    Allow the receptionist to find a reservation given the ID or the name of the guest.
    In case of many guest with the same name and surname returns the reservations made by both of them: the receptionist can discriminate the users by ID.
    Anyway, a message will alert the user about that.
    """
    if not session.get('logged_in'):
        abort(401)
    reserv = []
    n_res = 0
    mappa = {}

    if request.method == "GET":
        if request.args.get("id_res"):
            r = {"id_res": request.args.get("id_res")}
            reserv.append(
                reserv_info(
                    get_item("reservations", "id_res",
                             request.args.get("id_res"))))
            if len(reserv) > 1:
                mappa[
                    "msg"] = "An error occured: more than one reservation has the selected ID. Check the database!"
                mappa["error"] = "TRUE"
        elif request.args.get("surname"):
            surnames = get_item("guests", "surname",
                                request.args.get("surname"))
            if request.args["name"]:
                names = set(
                    get_item("guests", "name", request.args.get("name")))
                guests = list(set(surnames).intersection(names))
            else:
                guests = surnames
            if len(guests) > 1:
                mappa[
                    "msg"] = "More than one guest matches your search. Be careful!"
                mappa["error"] = "TRUE"
            for guest in guests:
                res = get_item("reservations", "id_guest", guest[0])
                reserv.append(
                    reserv_info(
                        get_item("reservations", "id_guest", guest[0])[0]))
                n_res = n_res + len(res)

    if request.method == "POST":
        lista = []
        for field in [
                "name", "surname", "checkin", "checkout", "room", "address",
                "info"
        ]:
            lista.append(request.form[field])
        #Passo la lista alla funzione di Gio e ottengo un feedback (???) ********************************
        mappa["msg"] = "Database aggiornato correttamente"
        #Regenerate list of resrvations
        if request.form["id_res"]:
            r = {"id_res": request.form["id_res"]}
            reserv.append(
                reserv_info(
                    get_item("reservations", "id_res",
                             request.args.get("id_res"))))
            if len(reserv) > 1:
                mappa[
                    "msg"] = "An error occured: more than one reservation has the selected ID. Check the database!"
                mappa["error"] = "TRUE"
        elif request.form["surname"]:
            surnames = get_item("guests", "surname", request.form["surname"])
            if request.form["name"]:
                names = set(get_item("guests", "name", request.form["name"]))
                guests = list(set(surnames).intersection(names))
            else:
                guests = surnames
            if len(guests) > 1:
                mappa[
                    "msg"] = "More than one guest matches your search. Be careful!"
                mappa["error"] = "TRUE"
            for guest in guests:
                res = get_item("reservations", "id_guest", guest[0])
                reserv.append(
                    reserv_info(
                        get_item("reservations", "id_guest", guest[0])[0]))
                n_res = n_res + len(res)

    mappa["n_res"] = n_res
    mappa["reservations"] = reserv
    print mappa
    template = env.get_template("reservations.html")
    return template.render(mappa)
Example #16
0
def play(player):

    op = -1
    while op != '0':
        op = input(
            'Here you start your adventure!\n0.Exit\n1.Stash\n2.Combat\n3.View character\n4.Level up\nR.'
        )
        os.system('cls')
        if op == '0':
            return
        elif op == '1':
            items = db.get_player_items(player)

            if items:
                # IF player have items on statsh
                print('Welcome to stash!!')
                print('This is your items:')
                for i in items:
                    print(i.id, '-', i.name)
                op = input('Select your item to equip: ')
                item = db.get_item(op)
                os.system('cls')
                db.equip_item(player, item)
                print(item.name + ' equipped!')
                player = db.get_player(player.id)
            else:
                # Player dont have any items on stash
                print('You have no items :(\nKill some mobs to get some items')

        elif op == '2':

            os.system('cls')
            print('1.Floresta\n2.Deserto\n3.Caverna')

            op = input('R.')
            os.system('cls')
            if op == '1' and db.get_player_caves(player, 0) == '0':
                print('You have entered into the forest.')
                t.sleep(1.5)
                enemy1 = c.player('Mosquito', 1, 5, 1, 1, 5, 5)
                enemy2 = c.player('Cobra', 2, 10, 1, 1, 10, 15)
                enemy3 = c.player('Urso', 3, 15, 1, 1, 15, 13, 13)
                enemy4 = c.player('Leão', 4, 20, 1, 1, 20, 15, 15)
                enemy5 = c.player('Ent',
                                  5,
                                  40,
                                  1,
                                  1,
                                  40,
                                  17,
                                  17,
                                  item_equipped=1)

                if player.fight(enemy1) == True:
                    if player.fight(enemy2) == True:
                        if player.fight(enemy3) == True:
                            if player.fight(enemy4) == True:
                                if player.fight(enemy5) == True:

                                    item = db.get_item(1)
                                    os.system('cls')
                                    print('You complete the Forest, Gratzz!')
                                    print('Here is your reward!')
                                    print(item.name +
                                          ' has been added to your stash!')
                                    db.att_item(player, item)
                                    db.update_player_caves(player, 0, '1')
                                    db.update_player_caves(player, 1, '0')
                                    t.sleep(3.5)

            elif op == '2' and db.get_player_caves(player, 1) == '0':
                print('You have entered into the deserto.')
                t.sleep(1.5)
                enemy1 = c.player('Calango', 1, 5, 1, 1, 5, 5)
                enemy2 = c.player('Camelo', 2, 10, 1, 1, 10, 15)
                enemy3 = c.player('Babuíno', 3, 15, 1, 1, 15, 13, 13)
                enemy4 = c.player('Minhocão', 4, 20, 1, 1, 20, 15, 15)
                enemy5 = c.player('Escorpião Gigante', 5, 40, 1, 1, 40, 17, 17)
                enemy6 = c.player('Mumia', 6, 60, 1, 1, 60, 19, 19)
                enemy7 = c.player('Esfinge',
                                  7,
                                  80,
                                  1,
                                  1,
                                  80,
                                  21,
                                  21,
                                  item_equipped=2)

                if player.fight(enemy1):
                    if player.fight(enemy2):
                        if player.fight(enemy3):
                            if player.fight(enemy4):
                                if player.fight(enemy5):
                                    if player.fight(enemy6):
                                        if player.fight(enemy7):

                                            item = db.get_item(3)
                                            os.system('cls')
                                            print(
                                                'You complete the deserto, Gratzz!'
                                            )
                                            # colocar condição se o item já existir no inventário do jogador
                                            print('Here is your reward!')
                                            print(
                                                item.name +
                                                ' has been added to your stash!'
                                            )
                                            db.att_item(player, item)

                                            player.lock_level(0)
                                            t.sleep(3.5)

            elif op == '3' and db.get_player_caves(player, 2) == '0':
                print('You have entered into the caverna.')
                t.sleep(1.5)
                enemy1 = c.player('Rato', 1, 5, 1, 1, 5, 5)
                enemy2 = c.player('Morcego', 2, 10, 1, 1, 10, 15)
                enemy3 = c.player('Goblin', 3, 15, 1, 1, 15, 13, 13)
                enemy4 = c.player('Kobold', 4, 20, 1, 1, 20, 15, 15)
                enemy5 = c.player('Esqueleto', 5, 40, 1, 1, 40, 17, 17)
                enemy6 = c.player('Orc', 6, 60, 1, 1, 60, 19, 19)
                enemy7 = c.player('Troll',
                                  7,
                                  80,
                                  1,
                                  1,
                                  80,
                                  21,
                                  2,
                                  item_equipped=2)
                enemy8 = c.player('O ex da sua mãe', 8, 100, 1, 1, 100, 23, 23)
                enemy9 = c.player('Dragão',
                                  9,
                                  110,
                                  1,
                                  1,
                                  110,
                                  23,
                                  23,
                                  item_equipped=3)

                if player.fight(enemy1):
                    if player.fight(enemy2):
                        if player.fight(enemy3):
                            if player.fight(enemy4):
                                if player.fight(enemy5):
                                    if player.fight(enemy6):
                                        if player.fight(enemy7):
                                            if player.fight(enemy8):
                                                if player.fight(enemy9):

                                                    item = db.get_item(3)
                                                    os.system('cls')
                                                    print(
                                                        'You complete the caverna, Gratzz!'
                                                    )
                                                    print(
                                                        'Here is your reward!')
                                                    print(
                                                        item.name +
                                                        ' has been added to your stash!'
                                                    )
                                                    db.att_item(player, item)
                                                    t.sleep(3.5)

        elif op == '3':
            # Show player ifo
            player.show()
            print()

        elif op == '4':
            # Level up!
            player.levelUp()

        else:
            print('invalid option')
Example #17
0
def sudo():
    if 'username' in session:
        sudo = get_item("users", "user", session["username"])[0][2]
        return sudo
    return False
Example #18
0
def reserv_page():
    """
    reserv()
    Allow the receptionist to find a reservation given the ID or the name of the guest.
    In case of many guest with the same name and surname returns the reservations made by both of them: the receptionist can discriminate the users by ID.
    Anyway, a message will alert the user about that.
    """
    if not session.get('logged_in'):
        abort(401)
    reserv = []
    n_res = 0
    mappa = {}
    
    if request.method == "GET":
        if request.args.get("id_res"):
            r = {"id_res" : request.args.get("id_res")}
            reserv.append(reserv_info(get_item("reservations", "id_res", request.args.get("id_res"))))
            if len(reserv) > 1:
                mappa["msg"] = "An error occured: more than one reservation has the selected ID. Check the database!"
                mappa["error"] = "TRUE"
        elif request.args.get("surname"):
            surnames = get_item("guests", "surname", request.args.get("surname"))
            if request.args["name"]:
                names = set(get_item("guests", "name", request.args.get("name")))
                guests = list(set(surnames).intersection(names))
            else:
                guests = surnames
            if len(guests) > 1:
                mappa["msg"] = "More than one guest matches your search. Be careful!"
                mappa["error"] = "TRUE"
            for guest in guests:
                res = get_item("reservations", "id_guest", guest[0])
                reserv.append(reserv_info(get_item("reservations", "id_guest", guest[0])[0]))
                n_res = n_res + len(res)
            
    if request.method == "POST":
        lista = []
        for field in ["name", "surname", "checkin", "checkout", "room", "address", "info"]:
            lista.append(request.form[field])
        #Passo la lista alla funzione di Gio e ottengo un feedback (???) ********************************
        mappa["msg"] = "Database aggiornato correttamente"
        #Regenerate list of resrvations
        if request.form["id_res"]:
            r = {"id_res" : request.form["id_res"]}
            reserv.append(reserv_info(get_item("reservations", "id_res", request.args.get("id_res"))))
            if len(reserv) > 1:
                mappa["msg"] = "An error occured: more than one reservation has the selected ID. Check the database!"
                mappa["error"] = "TRUE"
        elif request.form["surname"]:
            surnames = get_item("guests", "surname", request.form["surname"])
            if request.form["name"]:
                names = set(get_item("guests", "name", request.form["name"]))
                guests = list(set(surnames).intersection(names))
            else:
                guests = surnames
            if len(guests) > 1:
                mappa["msg"] = "More than one guest matches your search. Be careful!"
                mappa["error"] = "TRUE"
            for guest in guests:
                res = get_item("reservations", "id_guest", guest[0])
                reserv.append(reserv_info(get_item("reservations", "id_guest", guest[0])[0]))
                n_res = n_res + len(res)
            
    mappa["n_res"] = n_res
    mappa["reservations"] = reserv
    print mappa
    template = env.get_template("reservations.html")
    return template.render(mappa)