Esempio n. 1
0
def get_text_list(client: BaseClient):
    """パワーワードのリストを表示"""

    user = client.get_send_user_name()
    logger.debug("%s called 'text list'", user)
    msg = get_vocabularys()

    client.post(msg)
Esempio n. 2
0
 def ret(client: BaseClient):
     user = client.get_send_user_name()
     logger.debug("%s called 'hato 天気'", user)
     city_id = get_city_id_from_city_name(place)
     if city_id is None:
         client.post('該当する情報が見つからなかったっぽ!')
     else:
         weather_info = get_weather(city_id)
         client.post('```' + weather_info + '```')
Esempio n. 3
0
def version(client: BaseClient):
    """versionを表示する"""

    user = client.get_send_user_name()
    logger.debug("%s called 'hato version'", user)
    str_ver = "バージョン情報\n```"\
        "Version {}\n"\
        "Copyright (C) 2020 hato-bot Development team\n"\
        "https://github.com/nakkaa/hato-bot ```".format(VERSION)
    client.post(str_ver)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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
Esempio n. 7
0
    def ret(client: BaseClient):
        user = client.get_send_user_name()
        logger.debug("%s called 'hato altitude '", user)
        coordinates = None
        place_name = None
        place_list = split_command(place, 2)

        if len(place_list) == 2:
            try:
                coordinates = [str(float(p)) for p in reversed(place_list)]
            except ValueError:
                client.post('引数が正しくないっぽ......')
                return None

            place_name = ', '.join(reversed(coordinates))
        else:
            geo_data = get_geo_data(place_list[0] or '東京')
            if geo_data is not None:
                coordinates = [geo_data['lon'], geo_data['lat']]
                place_name = geo_data['place']

        if coordinates is not None:
            res = requests.get('https://map.yahooapis.jp/alt/V1/getAltitude',
                               {
                                   'appid': conf.YAHOO_API_TOKEN,
                                   'coordinates': ','.join(coordinates),
                                   'output': 'json'
                               },
                               stream=True)
            if res.status_code == 200:
                data_list = json.loads(res.content)
                if 'Feature' in data_list:
                    for data in data_list['Feature']:
                        if 'Property' in data and 'Altitude' in data['Property']:
                            altitude_ = data['Property']['Altitude']
                            altitude_str = '{:,}'.format(altitude_)
                            client.post(f'{place_name}の標高は{altitude_str}mっぽ!')
                            return res

        client.post('標高を取得できなかったっぽ......')
        return None
Esempio n. 8
0
def version(client: BaseClient):
    """versionを表示する"""

    user = client.get_send_user_name()
    logger.debug("%s called 'hato version'", user)
    str_ver = "バージョン情報\n```" \
              f"Version {VERSION}"

    if conf.GIT_COMMIT_HASH:
        str_ver += f" (Commit {conf.GIT_COMMIT_HASH[:7]})"
    else:
        try:
            repo = Repo()
            str_ver += f" (Commit {repo.head.commit.hexsha[:7]})"
        except (InvalidGitRepositoryError, GitCommandNotFound):
            pass

    str_ver += "\n" \
               "Copyright (C) 2020 hato-bot Development team\n" \
               "https://github.com/dev-hato/hato-bot ```"
    client.post(str_ver)
Esempio n. 9
0
 def ret(client: BaseClient):
     user = client.get_send_user_name()
     word = hato_ha_karaage(message)
     logger.debug("%s called 'hato >< %s'", user, word)
     msg = generator(word)
     client.post(msg)
Esempio n. 10
0
 def ret(client: BaseClient):
     user = client.get_send_user_name()
     logger.debug("%s called 'text delete'", user)
     msg = delete_vocabulary(int(power_word_id))
     client.post(msg)
Esempio n. 11
0
def show_random_text(client: BaseClient):
    """パワーワードの一覧からランダムで1つを表示する"""
    user = client.get_send_user_name()
    logger.debug("%s called 'text random'", user)
    msg = show_random_vocabulary()
    client.post(msg)
Esempio n. 12
0
 def ret(client: BaseClient):
     add_vocabulary(word)
     user = client.get_send_user_name()
     logger.debug("%s called 'text add'", user)
     client.post('覚えたっぽ!')