Exemplo n.º 1
0
    def ret(client: BaseClient):
        user = client.get_send_user_name()
        logger.debug("%s called 'hato amesh '", user)
        client.post('雨雲状況をお知らせするっぽ!')
        lat, lon = split_command(place, 2)

        url = weather_map_url(conf.YAHOO_API_TOKEN, lat, lon)
        req = requests.get(url, stream=True)
        f_name = "amesh.jpg"
        if req.status_code == 200:
            with open(f_name, 'wb') as weather_map_file:
                weather_map_file.write(req.content)
                client.upload(file=f_name, filename="amesh.png")

        os.remove(f_name)
Exemplo n.º 2
0
def amesh(client: BaseClient):
    """東京の天気を表示する"""

    user = client.get_send_user_name()
    logger.debug("%s called 'hato amesh'", user)
    client.post('東京の雨雲状況をお知らせするっぽ!')

    url = weather_map_url(conf.YAHOO_API_TOKEN, '35.698856', '139.73091159273')
    req = requests.get(url, stream=True)
    f_name = "amesh.jpg"
    if req.status_code == 200:
        with open(f_name, 'wb') as weather_map_file:
            weather_map_file.write(req.content)
            client.upload(file=f_name, filename="amesh.png")

    if os.path.exists(f_name):
        os.remove(f_name)
Exemplo n.º 3
0
    def ret(client: BaseClient):
        user = client.get_send_user_name()
        logger.debug("%s called 'hato amesh '", user)
        msg: str = '雨雲状況をお知らせするっぽ!'
        lat = None
        lon = None
        place_list = split_command(place, 2)

        if len(place_list) == 2:
            lat, lon = place_list
        else:
            geo_data = get_geo_data(place_list[0] or '東京')
            if geo_data is not None:
                msg = geo_data['place'] + 'の' + msg
                lat = geo_data['lat']
                lon = geo_data['lon']

        if lat is None or lon is None:
            client.post('雨雲状況を取得できなかったっぽ......')
            return None

        amesh_img = jma_amesh(lat=float(lat), lng=float(lon), zoom=10,
                              around_tiles=2)
        if amesh_img is None:
            client.post('雨雲状況を取得できなかったっぽ......')
            return None

        client.post(msg)
        with NamedTemporaryFile() as weather_map_file:
            amesh_img.save(weather_map_file, format='PNG')

            filename = ['amesh']
            ext = imghdr.what(weather_map_file.name)

            if ext:
                filename.append(ext)

            client.upload(file=weather_map_file.name,
                          filename=os.path.extsep.join(filename))
            return True

        return None