Ejemplo n.º 1
0
def test_get_weather():
    descr = weather.get_weather('Some Place', LAT, LON)
    print('Description:\n', descr)
    assert re.fullmatch(
        r'🏙 Some Place: сейчас (\w+\s?){1,3}\n'
        r'🌡 -?\d{1,2}(\.\d)?°C, ощущ. как -?\d{1,2}°C\n'
        r'💨 \d{1,2}(\.\d)?м/с с.\w{1,3}, 💦.\d{1,3}%\n'
        r'🌇 \d\d:\d\d ', descr)
Ejemplo n.º 2
0
 def post(self, request):
     received_body = request.body.decode('utf-8')
     received_body = json.loads(received_body)
     cities = received_body.get('cities')
     # print(cities)
     response_data = []
     for city in cities:
         # print(type(city))
         # print(city.get("city"))
         data = get_weather(city.get("city"))
         data["city_info"] = city
         response_data.append(data)
     response_data = self.wrap_json_response(data=response_data)
     return JsonResponse(data=response_data, safe=False)
Ejemplo n.º 3
0
def query_weather(inline_query):
    try:
        places_weather = [
            types.InlineQueryResultArticle(
                f'{k}',
                k,
                description='погода сейчас',
                input_message_content=types.InputTextMessageContent(
                    weather.get_weather(k, v.lat, v.lon)))
            for k, v in content.places.items()
        ]
        bot.answer_inline_query(inline_query.id,
                                places_weather,
                                cache_time=3000)
    except Exception as e:
        logger.error(e)
Ejemplo n.º 4
0
 def get(self, request):
     if not auth.already_authorized(request):
         response = self.wrap_json_response(code=ReturnCode.UNAUTHORIZED)
         return JsonResponse(data=response, safe=False)
     else:
         user = auth.get_user(request)
         cities = json.loads(user.focus_cities)
         response = []
         for city in cities:
             city_temp = city.split('-')[1]
             data = get_weather(city_temp)
             data["name"] = city
             response.append(data)
         response = self.wrap_json_response(data=response,
                                            code=ReturnCode.SUCCESS)
         return JsonResponse(data=response, safe=False)
Ejemplo n.º 5
0
def maprender_route():
    request_dict = request.get_json(force=True, silent=True)
    if not isinstance(request_dict, dict):
        response = json.jsonify({
            "status": 400,
            "message": "request_body not obtained"
        })
        response.status_code = 400
        return response

    x = request_dict.get("x", 0)
    y = request_dict.get("y", 0)
    center = request_dict.get("center", {})

    res_map = maprender.get_new_map(x, y, center)
    render_objects = maprender.get_objects(15, center)
    weather_info = weather.get_weather()

    return json.jsonify({
        "image_url": res_map,
        "weather": weather_info,
        "render_objects": render_objects
    })
Ejemplo n.º 6
0
def ask_weather(message):
    match = re.search(r'бот,? (?:покажи )?(погод\w|воздух) ([\w, ]+)',
                      message.text, re.I)
    if match:
        place = re.sub(r' в\b', '', match.group(2).strip())
        app = Nominatim(user_agent="wr-tg-bot")
        try:
            location = app.geocode(place).raw
        except AttributeError:
            return bot.reply_to(
                message,
                f'Есть такой населённый пункт {place}? ...не знаю. Введите запрос в в формате '
                '"Бот, погода Город" или "Бот, воздух Название Область".')
        if match.group(1).startswith('погод'):
            bot.send_chat_action(message.chat.id, 'typing')
            bot.send_message(
                message.chat.id,
                weather.get_weather(place, location['lat'], location['lon']))
        else:
            bot.send_chat_action(message.chat.id, 'typing')
            bot.send_message(
                message.chat.id,
                weather.get_air_quality(place, location['lat'],
                                        location['lon'])[1])
Ejemplo n.º 7
0
async def weather_worker(message):
    await types.ChatActions.typing(0.5)
    await message.reply(weather.get_weather(weather_token))