Пример #1
0
def send_cat_picture(update, context):
    user = get_or_create_user(db, update.effective_user, update.message.chat.id)
    cat_photos_list = glob('images/*cat.jpg')
    cat_pic_filename = choice(cat_photos_list)
    chat_id = update.effective_chat.id
    if user_voted(db, cat_pic_filename, user["user_id"]):
        rating = get_image_rating(db, cat_pic_filename)
        keyboard = None
        caption = f"Рейтинг картинки {rating}"
    else:
        keyboard = cat_rating_inline_keyboard(cat_pic_filename)
        caption = None 
    context.bot.send_photo(chat_id=chat_id, photo=open(cat_pic_filename, 'rb'),
                           reply_markup=keyboard, caption=caption)
Пример #2
0
def send_picture(update, context):
    user = get_or_create_user(db, update.effective_user,
                              update.message.chat_id)
    picture_list = glob('images/pic*.jpg')
    picture = choice(picture_list)
    chat_id = update.effective_chat.id
    if user_voted(db, picture, user['user_id']):
        rating = get_image_rating(db, picture)
        keyboard = None
        caption = f"Picture rating - {rating}"
    else:
        keyboard = cat_rating_inline_keyboard(picture)
        caption = None
    context.bot.send_photo(chat_id=chat_id,
                           photo=open(picture, 'rb'),
                           reply_markup=keyboard,
                           caption=caption)
Пример #3
0
def send_dog_picture(update, context):
    user = get_or_create_user(db, update.effective_user,
                              update.message.chat.id)
    dog_photo_list = glob("images/dog*.jp*g")
    dog_photo_filename = choice(dog_photo_list)
    chat_id = update.effective_chat.id
    if user_voted(db, dog_photo_filename, user['user_id']):
        rating = get_image_rating(db, dog_photo_filename)
        keyboard = None
        caption = f"Рейтинг картинки {rating}"
    else:
        keyboard = dog_rating_inline_keyboard(dog_photo_filename)
        caption = None
    context.bot.send_photo(chat_id=chat_id,
                           photo=open(dog_photo_filename, "rb"),
                           reply_markup=keyboard,
                           caption=caption)
Пример #4
0
def send_python_meme(update, context):
    user = get_or_create_user(db, update.effective_user, update.message.chat.id)
    logging.info('Запрошен мемасик')
    python_meme = glob('images/python*.jp*g')
    random_meme = choice(python_meme)
    chat_id = update.effective_chat.id
    if user_voted(db, random_meme, user['user_id']):
        rating = get_image_rating(db, random_meme)
        keyboard = None
        caption = f'Рейтинг мемасика: {rating}'
    else:
        keyboard = meme_rating_inline_keyboard(random_meme)
        caption = None
    context.bot.send_photo(
        chat_id=chat_id,
        photo=open(random_meme, 'rb'),
        reply_markup=keyboard,
        caption=caption
        )
Пример #5
0
def test_user_voted_false(mongodb):
    assert user_voted(mongodb, "images/cat_new.jpg", 1) is False
Пример #6
0
def test_user_voted_true(mongodb):
    assert user_voted(mongodb, "images/cat_new.jpg", 840852) is True