Ejemplo n.º 1
0
def handle_print_3_photos_from_walker(message):
    if message.text == 'Stop':
        WALKERS[hash(message.chat.id)] = None
        FIRST_NUMS[hash(message.chat.id)] = None
        return
    required_photo, photo_in_walker = FIRST_NUMS[hash(message.chat.id)], 0
    for photo in WALKERS[hash(message.chat.id)]:
        if photo_in_walker < required_photo:
            photo_in_walker += 1
            continue
        else:
            photo_in_walker += 3
        size = None
        for size_std in SIZES:
            tmp_size = photo.getSizes().get(size_std)
            if tmp_size is not None:
                if int(tmp_size["width"]) * int(
                        tmp_size["height"]) < MAX_PICTURE_SIZE:
                    size = size_std
                    break
        try:
            BOT.send_photo(message.chat.id, photo["sizes"][size]["source"])
        except Exception:
            continue
        required_photo += 1
        if required_photo == FIRST_NUMS[hash(message.chat.id)] + 3:
            break
    FIRST_NUMS[hash(message.chat.id)] += 3
    markup = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True)
    itembtn1 = types.KeyboardButton('Stop')
    itembtn2 = types.KeyboardButton('3 more photos')
    markup.add(itembtn1, itembtn2)
    BOT.send_message(message.chat.id, "More or stop??", reply_markup=markup)
    BOT.register_next_step_handler(message, handle_print_3_photos_from_walker)
Ejemplo n.º 2
0
def handle_authorization(message):
    AUTH_TOKENS[hash(message.chat.id)] = flickr_api.auth.AuthHandler()
    url = AUTH_TOKENS[hash(message.chat.id)].get_authorization_url("write")
    BOT.send_message(
        message.chat.id, "Follow this link, log in and accept the query:" +
        url + "\nThen copy everything from the next web-page and send me.")
    BOT.register_next_step_handler(message, handle_verifier)
Ejemplo n.º 3
0
def handle_search(message):
    markup = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True)
    itembtn1 = types.KeyboardButton('Photos in search')
    itembtn2 = types.KeyboardButton('User')
    markup.add(itembtn1, itembtn2)
    BOT.send_message(message.chat.id,
                     "Choose what you want to find.",
                     reply_markup=markup)
    BOT.register_next_step_handler(message, handle_search_what)
Ejemplo n.º 4
0
def get_receipe(message):
    if PERSON_INF.get((message.chat.id, 'name')) is None:
        BOT.send_message(message.chat.id, 'Вы ещё не прошли регистрацию')
        BOT.send_message(message.chat.id,
                         'Вам необходимо зарегестрироваться (напишите /reg)')
    else:
        BOT.send_message(
            message.chat.id,
            'Введите интересующие вас ингридиенты через запятую:')
        BOT.register_next_step_handler(message, get_ingredients)
Ejemplo n.º 5
0
def handle_search_what(message):
    if message.text == "User":
        BOT.send_message(message.chat.id,
                         "Write a user name, email or URL of the person.")
        BOT.register_next_step_handler(message, handle_find_person)
    elif message.text == "Photos in search":
        BOT.send_message(message.chat.id, "Write a tag or text to search by.")
        BOT.register_next_step_handler(message, handle_find_photo)
    else:
        BOT.send_message(
            message.chat.id,
            "Wrong input, are you sure you're following my instructions?"
            "If you want to continue, do everything from the start.")
Ejemplo n.º 6
0
def handle_upload(message):
    if USERS.get(hash(message.chat.id)) is None:
        try:
            flickr_api.set_auth_handler(
                "./users_data/{}/auth_token.dat".format(hash(message.chat.id)))
            USERS[hash(message.chat.id)] = flickr_api.test.login()
        except Exception:
            BOT.send_message(
                message.chat.id,
                "You're not authorized! Do it through /auth command")
            return
    BOT.send_message(message.chat.id, "Send me your photo.")
    BOT.register_next_step_handler(message, handle_upload_photo)
Ejemplo n.º 7
0
def handle_upload_photo(message):
    if not message.photo:
        BOT.send_message(
            message.chat.id,
            "There is no photo here! Try from the beginning and send me a photo!"
        )
        return
    photo = message.photo[-1]
    photo_id = photo.file_id
    url = "https://api.telegram.org/bot{}/getFile?file_id={}".format(
        BOT_TOKEN, photo_id)
    photo_path = json.loads(
        urllib.request.urlopen(url).read())['result']['file_path']
    url = "https://api.telegram.org/file/bot{}/{}".format(
        BOT_TOKEN, photo_path)
    URLS[hash(message.chat.id)] = url
    BOT.send_message(message.chat.id, "Write a title.")
    BOT.register_next_step_handler(message, handle_set_title)
Ejemplo n.º 8
0
def get_name(message):
    PERSON_INF[(message.chat.id, 'name')] = message.text
    BOT.send_message(message.chat.id, 'Какая у тебя фамилия?')
    BOT.register_next_step_handler(message, get_surname)
Ejemplo n.º 9
0
def handle_reg(message):
    if PERSON_INF.get((message.chat.id, 'name')) is not None:
        BOT.send_message(message.chat.id, 'Вы уже прошли регистрацию')
    else:
        BOT.send_message(message.chat.id, "Как у тебя имя?")
        BOT.register_next_step_handler(message, get_name)