Exemplo n.º 1
0
def show_dreams(from_nb=0):
    dreams = [dict(iddream = row[0], date=row[1], title=row[2], text=row[3]) for row in get_dream_page(from_nb)]
    pagination = paginate(from_nb, app.config['USER_PAGE_SIZE'], get_max_dreams())
    return render_template('dreams.html', 
            dreams=dreams, 
            previous_page = pagination[0],
            next_page = pagination[1])
Exemplo n.º 2
0
def callback_query_manage(bot: Bot, update: Update, groups: Tuple[str]):
    query: CallbackQuery = update.callback_query

    offset = int(groups[0])

    polls: List[Poll] = Poll.query(query.from_user.id,
                                   limit=MAX_POLLS_PER_USER)

    maybe_not_modified(query.edit_message_text,
                       text=manage_polls_message(polls, offset,
                                                 POLLS_PER_PAGE),
                       parse_mode=None,
                       disable_web_page_preview=True,
                       reply_markup=paginate(len(polls), offset,
                                             POLLS_PER_PAGE,
                                             manage_polls_callback_data))
Exemplo n.º 3
0
def manage(bot: Bot, update: Update):
    message: Message = update.message
    user_id = message.from_user.id

    polls = Poll.query(user_id, limit=MAX_POLLS_PER_USER)

    if len(polls) == 0:
        message.reply_text(text="you don't have any polls yet.",
                           reply_markup=InlineKeyboardMarkup([[
                               InlineKeyboardButton("create new poll",
                                                    callback_data=".start")
                           ]]))

    else:
        message.reply_text(manage_polls_message(polls, 0, POLLS_PER_PAGE),
                           parse_mode=None,
                           disable_web_page_preview=True,
                           reply_markup=paginate(len(polls), 0, POLLS_PER_PAGE,
                                                 manage_polls_callback_data))
Exemplo n.º 4
0
for x, y in zip(cat_urls, cat_names):
    # check if the category was already listed
    start_time = time.time()
    is_in_dir = check_files(y)
    if is_in_dir == True:
        print(
            f'Category {y} is already listed in {y}.csv. Proceeding with next category.'
        )
        w += 1
        continue
    else:
        product_list = []
        print(f'Retrieving data from category {w}/{N_cats} : {y}')
        # get the list of every page within tthe current product
        page_list = paginate(x, base_url)
        N_pages = len(page_list)
        v = 1
        for page in page_list:
            products = request(page)
            print(f'Getting items from page {v}/{N_pages}')
            parse(products, y)
            total_products = len(product_list)
            print('Total items: {}'.format(total_products))
            v += 1
            time.sleep(1)
        print('\n')
        time.sleep(1)
        output(y)
        w += 1
        time_taken = time.time() - start_time
Exemplo n.º 5
0
 def test_pagination_gets_right_text(self):
     pages, contents = paginate.paginate('<p>Hello</p><p>world</p>', 2, 5)
     assert contents == 'llo</'
Exemplo n.º 6
0
 def test_long_page_gets_paginated(self):
     pages, contents = paginate.paginate('<p>Hello</p><p>world</p>', 1, 5)
     assert pages > 1 
Exemplo n.º 7
0
 def test_out_of_range_raises(self):
     pages, contents = paginate.paginate('<p>Hello</p><p>world</p>', 2, 1000)
Exemplo n.º 8
0
 def test_short_pages_total_one_page(self):
     pages, contents = paginate.paginate('<p>Hello</p><p>world</p>', 1, 1000)
     assert pages == 1
Exemplo n.º 9
0
 def test_short_pages_pass_right_through(self):
     pages, contents = paginate.paginate('<p>Hello</p><p>world</p>', 1, 1000)
     assert contents == '<p>Hello</p><p>world</p>'