Пример #1
0
def send_categories(bot, update):
    try:
        if not update.message.location:
            return update.message.reply_text(
                get_message_by_key('coordinates_are_required'))

        lat, lng = update.message.location.latitude, update.message.location.longitude

        chanel = find_chanel(update.message.chat.id)
        chanel.set_coordinates(lat, lng)

        keyboard = build_inline_keyboard_categories(SELECTED_LANGUAGE)
        update.message.reply_text(
            get_message_by_key('places_and_establishments'),
            reply_markup=keyboard)
    except Exception as ex:
        print(ex)
Пример #2
0
def build_places(places, currentLat, currentLng):
    placesList = []

    for place in places:
        placeCoordinateLat = place['geometry']['location']['lat']
        placeCoordinateLng = place['geometry']['location']['lng']

        name = place['name'] if 'name' in place else get_message_by_key(
            'not_indicated')
        location = place[
            'vicinity'] if 'vicinity' in place else get_message_by_key(
                'not_indicated')
        rating = place['rating'] if 'rating' in place else get_message_by_key(
            'not_indicated')
        distance = get_distance(currentLat, currentLng, placeCoordinateLat,
                                placeCoordinateLng)
        direction = get_direction(currentLat, currentLng, placeCoordinateLat,
                                  placeCoordinateLng)

        placesList.append(Place(name, location, direction, distance, rating))

    return placesList
Пример #3
0
def send_places(bot, update, places):
    if (places):
        try:
            for place in places:
                bot.send_message(update.callback_query.message.chat.id,
                                 place.build_answer(),
                                 parse_mode=ParseMode.HTML)
        except Exception as ex:
            print(ex)
    else:
        not_found_message = get_message_by_key('not_found')
        bot.send_message(update.callback_query.message.chat.id,
                         not_found_message,
                         parse_mode=ParseMode.HTML)
Пример #4
0
def handle_coordinate(bot, update):
    try:
        if not update.message.location:
            return update.message.reply_text(
                get_message_by_key('coordinates_are_required'))

        lat, lng = update.message.location.latitude, update.message.location.longitude
        nearby_places = get_nearby_places(lat, lng, GOOGLE_PLACE_TOKEN,
                                          GOOGLE_PLACE_TYPE,
                                          GOOGLE_PLACE_DISTANCE)
        places_objects = take_by_limit(
            order_places(build_places(nearby_places, lat, lng)),
            int(GOOGLE_PLACE_LIMIT))

        return send_places(update, places_objects)
    except Exception as ex:
        print(ex)
Пример #5
0
 def get_answer_message_template(self):
     return get_message_by_key('need_coordinates')
Пример #6
0
def handle_start(bot, update):
    message = get_message_by_key('intro')
    update.message.reply_text(message, reply_markup=build_keyboard())
Пример #7
0
def build_keyboard():
    search_key = [KeyboardButton(get_message_by_key('search'), None, True)]
    return ReplyKeyboardMarkup([search_key], True)
Пример #8
0
def intro(bot, update):
    intro_message = get_message_by_key('intro')
    keyboard = build_keyboard()
    bot.send_message(update.message.chat.id,
                     intro_message,
                     reply_markup=keyboard)