現在地の明日の天気を取得

現在地の明日の天気を取得

毎回アレクサで聴くのは面倒なので
部屋に入った時、顔認識したら明日の天気を知らせるようにする

夜なら明日の天気
朝なら今日の天気とする

なので音声合成と画像認識、顔認識ができればOK

とりあえず明日の天気の取得をする

とりあえずChatGPT で調べる

Weather APIを使うようなので

無料で使える天気API「Free Weather API」の利用登録とキー発行手順
を参考に

https://www.weatherapi.com/signup.aspx
から登録しようとしたら
502 Bad Gateway
となるので

OpenWeatherMapAPI
を使うことにする

openweathermap.orgのAPIを使って天気表示

天候・気温予測サービス “OpenWeather” のAPIを活用する
を参考に

まずはAPI key の取得

https://home.openweathermap.org/users/sign_up
からできる

規約には
We will use information you provided for management and administration purposes, and for keeping you informed by mail, telephone, email and SMS of other products and services from us and our partners. You can proactively manage your preferences or opt-out of communications with us at any time using Privacy Centre. You have the right to access your data held by us or to request your data to be deleted. For full details please see the OpenWeather Privacy Policy.

I am 16 years old and over
I agree with Privacy Policy, Terms and conditions of sale and Websites terms and conditions of use

I consent to receive communications from OpenWeather Group of Companies and their partners:

System news (API usage alert, system update, temporary system shutdown, etc)
Product news (change to price, new product features, etc)
Corporate news (our life, the launch of a new service, etc)

日本語にすると
当社は、お客様から提供された情報を管理および管理の目的で使用し、また当社および当社のパートナーからの他の製品やサービスについて郵便、電話、電子メール、SMS でお客様に通知し続けるために使用します。お客様は、プライバシー センターを使用して、いつでも自分の設定を積極的に管理したり、当社とのコミュニケーションをオプトアウトしたりできます。あなたには、当社が保有する自分のデータにアクセスする権利、または自分のデータの削除を要求する権利があります。詳細については、OpenWeather プライバシー ポリシーをご覧ください。

私は16歳以上です
プライバシー ポリシー、販売条件、およびウェブサイトの利用条件に同意します
私は、OpenWeather Group of Companies およびそのパートナーからの連絡を受け取ることに同意します。

システムニュース(API使用状況のアラート、システムアップデート、システムの一時シャットダウンなど)
製品ニュース(価格変更、新製品特長など)
企業ニュース(私たちの生活、新サービスの開始など)

登録しようとしたら
既に去年登録していた….

キーは
Gmailに送られていてた

これを元に
https://qiita.com/K_Nemoto/items/51e124b3628106c6ef0a#apiを活用する
を参考に

import requests
import json
from pprint import pprint
url = “https://api.openweathermap.org/data/2.5/weather?zip={zip_place}&units=metric&appid={API_key}”
# xxxxx
url = url.format(zip_place = “任意の郵便番号,JP”, API_key = “取得したAPIキー”)

jsondata = requests.get(url).json()
pprint(jsondata)

print(“天気:”,jsondata[“weather”][0][“main”])
print(“天気詳細:”,jsondata[“weather”][0][“description”])

print(“都市名:”,jsondata[“name”])
print(“気温:”,jsondata[“main”][“temp”])
print(“体感気温:”,jsondata[“main”][“feels_like”])
print(“最低気温:”,jsondata[“main”][“temp_min”])
print(“最高気温:”,jsondata[“main”][“temp_max”])
print(“気圧:”,jsondata[“main”][“pressure”])
print(“湿度:”,jsondata[“main”][“humidity”])

print(“風速:”,jsondata[“wind”][“speed”])
print(“風の方角:”,jsondata[“wind”][“deg”])

で実行すると

{‘base’: ‘stations’,
‘clouds’: {‘all’: 0},
‘cod’: 200,
‘coord’: {‘lat’: 緯度, ‘lon’: 経度},
‘dt’: 1701631236,
‘id’: 0,
‘main’: {‘feels_like’: 4.12,
‘humidity’: 60,
‘pressure’: 1021,
‘temp’: 6.65,
‘temp_max’: 6.65,
‘temp_min’: 6.65},
‘name’: ‘Kawai’,
‘sys’: {‘country’: ‘JP’,
‘id’: 2008260,
‘sunrise’: 1701639567,
‘sunset’: 1701675443,
‘type’: 2},
‘timezone’: 32400,
‘visibility’: 10000,
‘weather’: [{‘description’: ‘clear sky’,
‘icon’: ’01n’,
‘id’: 800,
‘main’: ‘Clear’}],
‘wind’: {‘deg’: 288, ‘gust’: 5.36, ‘speed’: 3.58}}
天気: Clear
天気詳細: clear sky
都市名: Kawai
気温: 6.65
体感気温: 4.12
最低気温: 6.65
最高気温: 6.65
気圧: 1021
湿度: 60
風速: 3.58
風の方角: 288

となり入力した郵便番号の今日の天気が出る

とりあえず目的は今日、明日の天気の取得

他にも三時間ごとの天気とかもあるけど
今は不要
後々サーバー作って手持ちのスマホとかのGPSとリンクして
現在地の三時間ごとの天気で雨とか霧が出るなら注意とか
移動予定のところで滞在時間内に雨になりそうなら表示する感じか

パラメータとしては
https://hibi-update.org/other/openweathermap-api/
がわかりやすい

次に現在地のものを調べてみた

https://qiita.com/iwasan06/items/94db02186b17bf2d09fc
にあるけど
.erb なのでこれはrailsコード

位置情報取得にはGCPを使ってるが高いので別のものにする

https://zenn.dev/amuro/articles/96f61aff90e9da
にはスマホアプリへの現在地の実装方法が載ってるけど
今じゃない

https://note.com/ai_frontline/n/na22bd0ed7870
だとCHAT GPTと組み合わせだけど
それじゃない

むしろ
https://3pysci.com/openweathermap-5/
によれば

https://api.openweathermap.org/data/2.5/onecall?lat=
{lat}&lon={lon}&exclude={part}&appid={API key}

 となっているので

https://api.openweathermap.org/data/2.5/onecall?lat=33.44&lon=-94.04&appid={API key}

というように
緯度経度とAPI key があれば可能らしい
これなら現在地で取得可能

ということで
Pythonで現在地の緯度経度を取得するコードを作る

しかし考えた結果、現在地取得は不要
自宅の今日あすの天気と移動さきは移動さきの地名を入れるので
緯度経度で出すことはほぼない

次はopencv関連をやる

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です