Ejemplo n.º 1
0
def get_by_menu(database):
    view.clear()
    view.print_get_by_menu()

    choice = input('Input your choice: ')

    while True:
        while choice == '1':
            view.clear()
            min_core = input('Input min core value: ')
            max_core = input('Input max core value: ')

            if (int(min_core) < 0 or int(max_core) < 0
                    or int(min_core) > int(max_core)):
                print('Wrong values!')
                time.sleep(1)
            else:
                view.print_table(
                    database,
                    database.get_videocards_by_core(min_core, max_core))
                return True
        while choice == '2':
            view.clear()
            vendors = input('Input vendor separeted by space: ').split()
            print(vendors)

            view.print_table(database,
                             database.get_videocards_by_vendors(vendors))
            return True

        while choice == '3':
            return False
Ejemplo n.º 2
0
 def search_in_two_tables(self, table, table2, rel1, rel2, search_col, mods,
                          values):
     col_names, col_types, pkeys, fkeys = self.get_col_info(table)
     col_names2, col_types2, pkeys2, fkeys2 = self.get_col_info(table2)
     try:
         self.connect()
         self.cr.execute(
             psycopg2.sql.SQL(
                 "SELECT * FROM public.{0} JOIN public.{1} ON public.{0}.{2} = public.{1}.{3} WHERE {4};"
             ).format(
                 psycopg2.sql.Identifier(table),
                 psycopg2.sql.Identifier(table2), psycopg2.sql.SQL(rel1),
                 psycopg2.sql.SQL(rel2),
                 psycopg2.sql.SQL(" AND ".join([
                     (c + "=%s" if m[1] == '' else "(" + c + " BETWEEN " +
                      v[1].split()[0] + " AND " + v[1].split()[1] + ")")
                     for c, m, v in zip(search_col, mods, values)
                 ]))),
             tuple([v[1] for m, v in zip(mods, values) if m[1] != 'r']))
         data = self.cr.fetchall()
         view.print_table(col_names + col_names2, col_types + col_types2,
                          pkeys + pkeys2, fkeys + fkeys2, data)
     except (Exception, ps2.Error) as e:
         view.error(e)
     finally:
         self.close()
Ejemplo n.º 3
0
def teleport(table, input, x, y, cover_table, character):
    if input == 't':
        view.print_table(cover_table)
        input = data.getch()
        if input == 's' and table[y + 2][x] != '#':
            table[y] = data.replace_in_string(table[y], x, '.')
            cover_table[y] = data.replace_in_string(cover_table[y], x, '.')
            table[y + 2] = data.replace_in_string(table[y + 2], x, character)
            y = y + 2
        if input == 'w' and table[y - 2][x] != '#':
            table[y] = data.replace_in_string(table[y], x, '.')
            cover_table[y] = data.replace_in_string(cover_table[y], x, '.')
            table[y - 2] = data.replace_in_string(table[y - 2], x, character)
            y = y - 2
        if input == 'd' and table[y][x + 2] != '#':
            table[y] = data.replace_in_string(table[y], x, '.')
            cover_table[y] = data.replace_in_string(cover_table[y], x, '.')
            table[y] = data.replace_in_string(table[y], x + 2, character)
            x = x + 2
        if input == 'a' and table[y][x - 2] != '#':
            table[y] = data.replace_in_string(table[y], x, '.')
            cover_table[y] = data.replace_in_string(cover_table[y], x, '.')
            table[y] = data.replace_in_string(table[y], x - 2, character)
            x = x - 2
    o = [table, x, y]
    os.system("clear")
    return o
Ejemplo n.º 4
0
def select_menu(database):
    table_name = input('Input table name: ')

    if table_name not in database.table_names:
        return False
    else:
        view.clear()
        view.print_table(database, database.get_from_table(table_name),
                         table_name)
        return True
Ejemplo n.º 5
0
 def select_all(self, table):
     col_names, col_types, pkeys, fkeys = self.get_col_info(table)
     try:
         self.connect()
         qr = self.session.query(self.base.classes[table]).limit(1000)
         data = [[getattr(q, c) for c in col_names] for q in qr]
         view.print_table(col_names, col_types, pkeys, fkeys, data)
     except Exception as e:
         view.error(e)
         controller.selection()
     finally:
         self.close()
Ejemplo n.º 6
0
 def full_text_search(self, table, text_col, txt, search_mode=1):
     col_names, col_types, pkeys, fkeys = self.get_col_info(table)
     try:
         self.connect()
         data = self.session.execute(text("SELECT * FROM public.\"{}\" WHERE {} (to_tsvector({}) @@ to_tsquery('{}'));"
             .format(table, ("NOT" if search_mode == 1 else ""),
                     text_col, ('|' if search_mode == 1 else '&').join(txt)))).fetchall()
         view.print_table(col_names, col_types, pkeys, fkeys, data)
     except Exception as e:
         view.error(e)
     finally:
         self.close()
Ejemplo n.º 7
0
 def select_all(self, table):
     col_names, col_types, pkeys, fkeys = self.get_col_info(table)
     try:
         self.connect()
         self.cr.execute(
             psycopg2.sql.SQL("SELECT * FROM public.{};").format(
                 psycopg2.sql.Identifier(table)))
         data = self.cr.fetchall()
         view.print_table(col_names, col_types, pkeys, fkeys, data)
     except (Exception, ps2.Error) as e:
         view.error(e)
         controller.selection()
     finally:
         self.close()
Ejemplo n.º 8
0
 def search_in_two_tables(self, table, table2, rel1, rel2, search_col, mods, values):
     col_names, col_types, pkeys, fkeys = self.get_col_info(table)
     col_names2, col_types2, pkeys2, fkeys2 = self.get_col_info(table2)
     try:
         self.connect()
         data = self.session.execute(
             text("SELECT * FROM public.\"{0}\" JOIN public.\"{1}\" ON public.\"{0}\".{2} = public.\"{1}\".{3} WHERE {4};"
             .format(table, table2, rel1, rel2,
                     " AND ".join([(c+"=:"+c if m[1] == '' else "("+c+" BETWEEN "+v[1].split()[0]+" AND "+v[1].split()[1]+")")
                                                     for c, m, v in zip(search_col, mods, values)]))),
             dict([(c, v[1]) for c, m, v in zip(search_col, mods, values) if m[1] != 'r'])).fetchall()
         view.print_table(col_names+col_names2, col_types+col_types2, pkeys+pkeys2, fkeys+fkeys2, data)
     except Exception as e:
         view.error(e)
     finally:
         self.close()
Ejemplo n.º 9
0
def text_search_menu(database):
    view.clear()
    search_str = input('Input word or phrase to search: ')

    if view.print_table(database, database.full_text_search(search_str)):
        return True
    else:
        print(f'Cannot find \'{search_str}\'')
        return True
Ejemplo n.º 10
0
def run():
    choice_from_menu = False
    while not choice_from_menu:
        player_choice = menu.menu()
        if player_choice == '1' or player_choice == '2' or player_choice == '3':
            choice_from_menu = True
        else:
            print("\nThere is no such choice!")
            input()

    if player_choice == '1':
        os.system('clear')
        x = 3
        y = 3
        inventory = []
        table = t.create_table()
        cover_table = view.get_empty_table(table)
        coordinates_a_b = data.find_a_b(table)
        coordinates_water = data.find_water(table)
        coordinates_dolars = data.find_dolars(table)
        money = len(coordinates_dolars)
        coordinates_items = data.find_item(table)
        character = character_selection.character_selection()
        enter_pressed = False
        while not enter_pressed:
            os.system('clear')
            menu.rogulike_title()
            enter_input = input("Press ENTER to start\n")
            if enter_input == "":
                enter_pressed = True

        while True:
            inp = data.getch()
            if inp == "i":
                os.system("clear")
                print(inv.print_table(inventory))
                print("Your money:", colors.CBOLD + colors.CYELLOW,
                      money - len(coordinates_dolars), colors.CEND, "/",
                      colors.CBOLD + colors.CYELLOW, money, colors.CEND, "$")
                print("\nPress ENTER to return")
                quit_inventory = input()
            os.system("clear")
            w = moves.moves(table, inp, x, y, character)
            table = w[0]
            x = w[1]
            y = w[2]
            data.discover_table(table, cover_table, x, y)
            w = moves.teleport(table, inp, x, y, cover_table, character)
            table = w[0]
            x = w[1]
            y = w[2]
            data.discover_table(table, cover_table, x, y)
            w = moves.gate_teleport(table, cover_table, coordinates_a_b, x, y,
                                    character)
            x = w[0]
            y = w[1]
            table = w[2]
            moves.water(coordinates_water, x, y)
            coordinates_dolars = moves.dolars(coordinates_dolars, x, y)
            inventory = moves.get_inventory(coordinates_items, x, y, inventory)
            coordinates_items = moves.items(coordinates_items, x, y)
            data.discover_table(table, cover_table, x, y)
            view.print_table(cover_table)

    if player_choice == '2':
        os.system('clear')
        valid_input = False
        while not valid_input:
            os.system('clear')
            a = menu.options_menu()
            if a == '0':
                valid_input = True
                os.system('clear')
                run()

    if player_choice == '3':
        os.system('clear')
        os._exit(0)
Ejemplo n.º 11
0
def main():
    # initial level
    level = 'BOARD_1'

    # initial key
    key = ''

    menu_start.run()

    ui.print_message('\n\n\n LEVEL %s \n\n\n' % (level[-1]))
    time.sleep(1.0)
    util.clear_screen()

    pass_key_input = False

    while level != 'WIN' and level != 'QUIT' and level != 'LOSE':

        util.clear_screen()
        pass_key_input = False

        view.print_table(players.data_to_print(dictionaries.player))

        # Set up board
        global BOARD_1
        global BOARD_2
        global BOARD_3
        # global items_u_will_use
        # global coordonate_of_items_that_u_will_use
        # player = create_player()
        BOARD_1 = engine.create_board()
        BOARD_2 = engine.create_board()
        BOARD_3 = engine.create_board()
        BOARD_1, items_u_will_use_1, coordonate_of_items_that_u_will_use_1 = engine.create_final_board(BOARD_1, little_boss_1)
        BOARD_2, items_u_will_use_2, coordonate_of_items_that_u_will_use_2 = engine.create_final_board(BOARD_2, little_boss_2)
        BOARD_3, items_u_will_use_3, coordonate_of_items_that_u_will_use_3 = engine.create_final_board(BOARD_3, boss)
        BOARD_1 = engine.create_board()
        BOARD_2 = engine.create_board()
        BOARD_3 = engine.create_board()
        util.clear_screen()
        is_running = True
        while is_running:
            print()
            print("U entered first level")
            print()
            items_u_will_use_1, coordonate_of_items_that_u_will_use_1 = engine.items_and_coordonates_that_u_can_use(BOARD_1)
            (BOARD_1, items_u_will_use, coordonate_of_items_that_u_will_use_1) = engine.create_final_board(BOARD_1, little_boss_1)
            (BOARD_1, items_u_will_use_1, coordonate_of_items_that_u_will_use_1) = engine.put_player_on_board(BOARD_1, little_boss_1)
            engine.move_something_and_gate(BOARD_1, player, little_boss_1, gate_1)

            if player['player_life'] > 0:
                print()
                print("U entered second level")
                print()
            items_u_will_use_2, coordonate_of_items_that_u_will_use_2 = engine.items_and_coordonates_that_u_can_use(BOARD_2)
            (BOARD_2, items_u_will_use_2, coordonate_of_items_that_u_will_use_2) = engine.create_final_board(BOARD_2, little_boss_2)
            engine.move_something_and_gate(BOARD_2, player, little_boss_2, gate_2)

            if player['player_life'] > 0:
                print()
                print("U entered the third level")
                print()
            items_u_will_use_3, coordonate_of_items_that_u_will_use_3 = engine.items_and_coordonates_that_u_can_use(BOARD_3)
            (BOARD_3, items_u_will_use_3, coordonate_of_items_that_u_will_use_3) = engine.create_final_board(BOARD_3, boss)
            engine.move_something_and_gate(BOARD_3, player, boss, gate_3)
            # ui.display_board(board)

        key = util.key_pressed()
        if key == 'q':
            is_running = False
        # elif key == 'i':
        #     print(inventory)
        is_running = False
        # util.clear_screen()
        print(key)
        # break
            # ui.display_board(board)

        key = util.key_pressed()
        # if key == 'q':
        #     is_running = False
        # elif key == 'i':
        #     print(inventory)

        # util.clear_screen()
        print(key)

        # Display essential info
        ui.print_player_essential_atributes(dictionaries.player)

        # Display board
        ui.display_board(board)

        # Message panel intoduction (always displayed)
        ui.print_message('  MESSAGE PANEL \n' + 17 * '-' + '\n')

        # Interaction whit items

        # Display inventory
        if key == 'i':
            ui.print_message('This is your inventory content: ')
            ui.print_table(dictionaries.inventory)

        # Interaction with other characters

        # Insert secret code
        if key == "c":
            engine.use_secret_code(dictionaries.player, dictionaries.others, level, dictionaries.codes)

        # Gate and level change handling
        # if engine.player_enters_gate() != level:
            # util.clear_screen()
            # level = engine.player_enters_gate()

            if level == 'BOARD_2' or level == 'BOARD_3':
                dictionaries.player['position_y'] = 15
                dictionaries.player['position_x'] = 3

            if level == 'WIN':
                pass_key_input = True
                pass
            else:
                ui.print_message('\n\n\n LEVEL %s \n\n\n' % (level[-1]))
                time.sleep(1.0)
                util.clear_screen()
                pass_key_input = True

        # Player input
        if pass_key_input is False:
            key = util.key_pressed()

        # Movement
        if pass_key_input is False:
            pass
        # engine.movement()

        # Check if quit
        if key == 'q':
            quit_assertion = ''
            while quit_assertion != 'y' and quit_assertion != 'n':
                util.clear_screen()
                print('Are you sure you want to quit? ( Y / N )')
                quit_assertion = util.key_pressed()
                if quit_assertion == 'y':
                    level = 'QUIT'
                elif quit_assertion == 'n':
                    pass
                else:
                    pass

        if dictionaries.player['player_life'] == 0:
            level = 'LOSE'

    if level == 'WIN':
        util.clear_screen()
        ui.display_board(board)
        print(text2art("VICTORY!", font='block', chr_ignore=True))

    elif level == 'LOSE':
        util.clear_screen()
        ui.display_board(board)
        print(text2art("GAME OVER!", font='block', chr_ignore=True))
        time.sleep(10.7)

    print('\n\n\n Goodbye, see you soon!')
    time.sleep(1.0)
def main():
        
    
    prev_addr = os.getenv('HTTP_REFERER')
    prev_page = None
    if prev_addr != None:
        prev_page = prev_addr.split('/')[-1]

    if prev_page == PIVOT:
    
        form = cgi.FieldStorage()

        # get values sent via form

        row = form.getvalue('row')
        col = form.getvalue('col')
        val = form.getvalue('val')
        mode = form.getvalue('mode')
        searchby = form.getvalue('searchby')
        search = form.getvalue('search')

        try:

            all_data = model.get_all_data(model.DATA_FILE)
            interval = model.att_intervals()

            # get key elements from row and column

            if row in ['Season', 'Tm']:
                #get unique values for row 
                unique_row = model.create_keys(all_data, row)
                #row header for table str 
                unique_row_str = unique_row
            else:
                #find the min and max value for row
                row_min_max = model.min_max(all_data, row)
                #row header
                unique_row = model.get_bin_header(row_min_max[0],row_min_max[1], interval[row])
                #row header for table str
                unique_row_str = model.get_bin_str(unique_row)

            if col in ['Season', 'Tm']:
                #get unique values for col
                unique_col = model.create_keys(all_data, col)
                #row header for table col
                unique_col_str = unique_col
            else:
                #find the min and max value for col
                col_min_max = model.min_max(all_data, col)
                #col header
                unique_col = model.get_bin_header(col_min_max[0],col_min_max[1], interval[col])
                #col header for table str 
                unique_col_str = model.get_bin_str(unique_col)

            # if search query is passed, filter unique_row or unique_col using the query
            search_row = row
            search_col = col
            if searchby and search:
                
                if row == searchby:
                    temp = [item for item in unique_row if item == search]
                    if temp != []:
                        unique_row = temp
                        unique_row_str = temp
                    else:
                        #item not in csv file
                        raise ValueError(SEARCH_ERROR)
                elif col == searchby:

                    temp = [item for item in unique_col if item == search]

                    if temp != []:
                        unique_col = temp
                        unique_col_str = temp
                    else:
                        raise ValueError(SEARCH_ERROR)

                


            # get pivot table values
            pvt_vals = model.get_pvt_vals(
                all_data,
                row,
                col,
                val,
                mode,
                unique_row,
                unique_col,
                )

            # add sum of rows and columns to pvt_vals
            pvt_vals = model.pvt_table_total(pvt_vals)

            # add total to the end of row header and column header
            unique_row_str.append('Total')
            unique_col_str.append('Total')
            
            # get pivot table title
            title_str = view.create_title(row, col, val, mode, searchby, search)
            
            # get html of the pivot table contents
            html_str = view.create_table_str(pvt_vals, unique_row_str)

            # print html_str
            if html_str:
                view.print_table(pvt_vals, title_str,row, unique_row_str, unique_col_str, html_str)
                
        except ValueError, val_err:

            view.print_error(val_err)
Ejemplo n.º 13
0
def main_menu():
    while True:
        view.show_main_menu()
        option = input()
        if re.match(r'^[1-5]{1}$', option):
            while True:
                view.tables_names()
                chosen_table = input()
                if re.match(r'^[1-6]{1}$', chosen_table):
                    table = tables[chosen_table]
                    if option == '1':
                        notes = DB.select(table)
                        view.print_orm_table(notes)
                    elif option == '2':
                        res = insert_into_table(chosen_table)
                        if not res:
                            print("Data wasn't inserted")
                        else:
                            print("Successfully inserted")
                    elif option == '3':
                        res = update_table(chosen_table)
                        if not res:
                            print("Data wasn't updated")
                        else:
                            print("Operation successfull")
                    elif option == '4':
                        res = delete_from_table(chosen_table)
                        if not res:
                            print("Data wasn't deleted")
                        else:
                            print("Operation successfull")
                    elif option == '5':
                        text = input("Input text to search: ")
                        view.fts_mode()
                        mode = input()
                        if re.match(r'^[1,2]{1}$', mode):
                            notes = fts_table(text, mode, chosen_table)
                            view.print_table(chosen_table, notes)
                        elif continue_or_back == '0':
                            break
                        else:
                            print("No such option. Check your input")
                elif chosen_table == '0':
                    break
                else:
                    print("No such option. Check your input")
                view.back_to_menu()
                back_to_menu = input()
                if back_to_menu == '0':
                    continue
                elif back_to_menu == '1':
                    break
                else:
                    print("No such option. Check your input")
        elif option == '6':
            view.print_table('3', game_price_range())
        elif option == '7':
            dev = input("Input developers names separated with comma: ")
            dev = dev.split(', ')
            for dev_list in game_of_developers(dev):
                view.print_table('3', dev_list)

        elif option == '8':
            num_of_rand = input("Number of random players\n")
            res = model.random_author(num_of_rand)
            if not res:
                print("Data wasn't updated")
            else:
                print("Successfully updated")
        elif option == '9':
            os.system("cls")
        elif option == '0':
            exit()
        else:
            print("No such option. Check your input")
Ejemplo n.º 14
0
def main():
    MUSIC_FILE = "Cookie Monster Sings C is for Cookie.wav"
    mixer.init()
    mixer.music.load(MUSIC_FILE)
    mixer.music.play()
    view.print_images(data_manager.read_file_record('ascii-art.txt'))
    view.start_descriptions()
    # initial level
    level = 'BOARD_1'

    # initial key
    key = ''

    menu_start.run()

    ui.print_message('\n\n\n LEVEL %s \n\n\n' % (level[-1]))
    time.sleep(1.0)
    util.clear_screen()

    pass_key_input = False

    while level != 'WIN' and level != 'QUIT' and level != 'LOSE':

        util.clear_screen()
        pass_key_input = False

        view.print_table(players.data_to_print(dictionaries.player))

        # Set up board
        board = engine.create_board(dictionaries.BOARD[level])
        board = engine.put_other_on_board(board, dictionaries.others, level)
        board = engine.put_item_on_board(board, dictionaries.items, level)
        board = engine.put_player_on_board(board, dictionaries.player)

        # Display essential info
        ui.print_player_essential_atributes(dictionaries.player)

        # Display board
        ui.display_board(board)

        # Message panel intoduction (always displayed)
        ui.print_message('  MESSAGE PANEL \n' + 17 * '-' + '\n')

        # Interaction whit items
        engine.item_vs_player(dictionaries.inventory, dictionaries.items,
                              dictionaries.player, level, dictionaries.items)

        # Display inventory
        if key == 'i':
            ui.print_message('This is your inventory content: ')
            ui.print_table(dictionaries.inventory)

        # Display statistics
        if key == "p":
            engine.show_statistics(dictionaries.player)

        # Interaction with other characters
        if engine.player_meets_other(dictionaries.others, dictionaries.player,
                                     level, board) != False:
            other = engine.player_meets_other(dictionaries.others,
                                              dictionaries.player, level,
                                              board)
            if dictionaries.others[other]['other_type'] == 'enemy':
                engine.fight(dictionaries.player, dictionaries.others, other,
                             dictionaries.inventory, dictionaries.items)
            elif dictionaries.others[other]['other_type'] == 'quiz':
                engine.player_vs_other_quiz(
                    dictionaries.player, other, dictionaries.others,
                    dictionaries.inventory,
                    dictionaries.others[other]['questions'])

        # Insert secret code
        if key == "c":
            engine.use_secret_code(dictionaries.player, dictionaries.others,
                                   level, dictionaries.codes)

        # Gate and level change handling
        if engine.player_enters_gate(
                level, dictionaries.BOARD, dictionaries.player, key,
                dictionaries.inventory, dictionaries.others) != level:
            util.clear_screen()
            level = engine.player_enters_gate(level, dictionaries.BOARD,
                                              dictionaries.player, key,
                                              dictionaries.inventory,
                                              dictionaries.others)

            if level == 'BOARD_2' or level == 'BOARD_3':
                dictionaries.player['position_y'] = 15
                dictionaries.player['position_x'] = 3

            if level == 'WIN':
                pass_key_input = True
                pass
            else:
                ui.print_message('\n\n\n LEVEL %s \n\n\n' % (level[-1]))
                time.sleep(1.0)
                util.clear_screen()
                pass_key_input = True

        # Player input
        if pass_key_input == False:
            key = util.key_pressed()

        # Movement
        if pass_key_input == False:
            engine.movement(board, dictionaries.player, key,
                            dictionaries.others)

        # Check if quit
        if key == 'q':
            quit_assertion = ''
            while quit_assertion != 'y' and quit_assertion != 'n':
                util.clear_screen()
                print('Are you sure you want to quit? ( Y / N )')
                quit_assertion = util.key_pressed()
                if quit_assertion == 'y':
                    level = 'QUIT'
                elif quit_assertion == 'n':
                    pass
                else:
                    pass

        if dictionaries.player['player_life'] == 0:
            level = 'LOSE'

    if level == 'WIN':
        util.clear_screen()
        ui.display_board(board)
        print(text2art("VICTORY!", font='block', chr_ignore=True))

    elif level == 'LOSE':
        util.clear_screen()
        ui.display_board(board)
        print(text2art("GAME OVER!", font='block', chr_ignore=True))

        time.sleep(10.7)

    ui.authors_presentation()
    players.add_results(players.count_points(), "results.txt")
    print('\n\n\n Goodbye, see you soon!')
    time.sleep(1.0)

    with Image.open("cookiemonster.jpg") as img:
        img.show()