Esempio n. 1
0
def meme_picture_raiting(update, context):
    update.callback_query.answer()
    callback_type, image_name, vote = update.callback_query.data.split('|')
    vote = int(vote)
    user = get_or_create_user(db, update.effective_user, update.effective_chat.id)
    save_meme_image_vote(db, user, image_name, vote)
    rating = get_image_rating(db, image_name)
    update.callback_query.edit_message_caption(caption=f'Рейтин мемасика: {rating}')
Esempio n. 2
0
def cat_picture_rating(update, context):
    update.callback_query.answer()
    callback_type, image_name, vote = update.callback_query.data.split("|")
    vote = int(vote)
    user = get_or_create_user(db, update.effective_user, update.effective_chat.id)
    save_cat_image_vote(db, user, image_name, vote)
    rating = get_image_rating(db, image_name)
    update.callback_query.edit_message_caption(caption=f"Рейтинг картинки {rating}")
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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
        )
Esempio n. 7
0
def test_get_image_rating(mongodb):
    assert get_image_rating(mongodb, "images/cat_new.jpg") == 3
    assert get_image_rating(mongodb, "images/no_image.jpg") == 0