예제 #1
0
def parse_location(message: types.Message):
    ll = re.match(r'^\s*(-?\d+\.\d+),\s*(-?\d+\.\d+)\s*$', message.text or '')
    if message.location:
        return Location(lon=message.location.longitude,
                        lat=message.location.latitude)
    elif ll:
        return Location(lat=float(ll.group(1)), lon=float(ll.group(2)))
    return None
예제 #2
0
async def set_loc(message):
    info = await get_user(message.from_user)
    if not info.review or not info.review_ctx:
        raise SkipHandler
    # Save location and continue the review
    location = Location(message.location.longitude, message.location.latitude)
    info.location = location
    await start_review(message.from_user, *info.review_ctx)
예제 #3
0
async def set_loc(message):
    location = Location(message.location.longitude, message.location.latitude)
    info = await get_user(message.from_user)
    info.location = location
    if info.is_moderator():
        # Suggest review mode
        kbd = types.InlineKeyboardMarkup().add(
            types.InlineKeyboardButton(tr(('review', 'start')),
                                       callback_data='start_review'))
    else:
        kbd = get_buttons()
    await message.answer(tr('location'), reply_markup=kbd)
예제 #4
0
async def new_keywords(message: types.Message, state: FSMContext):
    keywords = split_tokens(message.text)
    if not keywords:
        await message.answer(tr(('new_poi', 'no_keywords')))
        return
    # Create a POI
    data = await state.get_data()
    poi = POI(name=data['name'],
              location=Location(lat=data['lat'], lon=data['lon']),
              keywords=' '.join(keywords))
    await state.set_data({'poi': poi})
    await EditState.confirm.set()
    await print_edit_options(message.from_user, state,
                             tr(('new_poi', 'confirm')))
예제 #5
0
def run():
    if len(sys.argv) < 3:
        print('Usage: {} test_map <str_id1,strid2,...> [<map.jpg>]'.format(
            sys.argv[0]))
        sys.exit(1)

    locations = []
    with sqlite3.connect(DATABASE) as conn:
        for str_id in sys.argv[2].split(','):
            cursor = conn.execute("select lon, lat from poi where str_id = ?",
                                  (str_id, ))
            row = cursor.fetchone()
            if not row:
                print(f'Cannot find {str_id} in the database.')
                sys.exit(2)
            locations.append(Location(lon=row[0], lat=row[1]))

    logging.basicConfig(level=logging.INFO)
    fp = get_map(locations)
    filename = 'test_map.jpg' if len(sys.argv) < 4 else sys.argv[3]
    with open(filename, 'wb') as f:
        data = fp.read()
        f.write(data)
    fp.close()
예제 #6
0
async def save_location(message: types.Message):
    location = Location(message.location.longitude, message.location.latitude)
    info = await get_user(message.from_user)
    info.location = location