From c949ac6771316466256fd7fe96c46d54ab8da74d Mon Sep 17 00:00:00 2001 From: quojama Date: Sun, 12 May 2024 05:06:59 +0900 Subject: [PATCH 1/2] yamagata weather --- src/cogs/wt_task.py | 10 +++++++--- src/libs/utils.py | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cogs/wt_task.py b/src/cogs/wt_task.py index 90efd62..fa7d893 100644 --- a/src/cogs/wt_task.py +++ b/src/cogs/wt_task.py @@ -33,8 +33,12 @@ async def printer(self): result = get_what_today(this_month, this_day) # 東京地方の天気を取得。citycode一覧 "https://weather.tsukumijima.net/primary_area.xml" - citycode = 130010 - weather = get_weather(citycode) + citycode = "130010" + tokyo_weather = get_weather(citycode) + + # 山形の天気を取得。 + citycode = "060010" + yamagata_weather = get_weather(citycode) # ChatGPTで雑学を取得 trivia = await get_trivia() @@ -65,7 +69,7 @@ async def printer(self): embed = discord.Embed() embed.color = discord.Color.green() embed.title = f"{good_morning}{this_month}月{this_day}日 朝の7時です。" - embed.description = f"### 💡 今日はなんの日?\n{result}\n### 📚 今日の雑学\n{trivia}\n(Powered by [gpt-4-1106-preview](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo))\n### 💹 相場\n{market_text}\n### ⛅ 今日の天気\n{weather}" # noqa: E501 + embed.description = f"### 💡 今日はなんの日?\n{result}\n### 📚 今日の雑学\n{trivia}\n(Powered by [gpt-4-1106-preview](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo))\n### 💹 相場\n{market_text}\n### ⛅ 今日の天気\n{tokyo_weather}\n{yamagata_weather}" # noqa: E501 await channel.send(embed=embed) # デプロイ後Botが完全に起動してからタスクを回す diff --git a/src/libs/utils.py b/src/libs/utils.py index 80ab01a..4f25e12 100644 --- a/src/libs/utils.py +++ b/src/libs/utils.py @@ -42,7 +42,7 @@ def get_what_today(this_month: int, this_day: int) -> str: return result -def get_weather(citycode: int): +def get_weather(citycode: str): url = "https://weather.tsukumijima.net/api/forecast" # citycode一覧"https://weather.tsukumijima.net/primary_area.xml" @@ -52,17 +52,17 @@ def get_weather(citycode: int): json = res.json() # date = json["forecasts"][0]["date"] - district = json["location"]["district"] + city = json["location"]["city"] # body_text = json["description"]["bodyText"] weather = json["forecasts"][0]["detail"]["weather"] weather = weather.replace(" ", "") # min_temp = json["forecasts"][0]["temperature"]["min"]["celsius"] - # max_temp = json["forecasts"][0]["temperature"]["max"]["celsius"] + max_temp = json["forecasts"][0]["temperature"]["max"]["celsius"] chanceOfRain_morning = json["forecasts"][0]["chanceOfRain"]["T06_12"] chanceOfRain_evening = json["forecasts"][0]["chanceOfRain"]["T12_18"] chanceOfRain_night = json["forecasts"][0]["chanceOfRain"]["T18_24"] - result = f"- {district}: {weather}\n- ☔ 朝: {chanceOfRain_morning} | 昼: {chanceOfRain_evening} | 晩: {chanceOfRain_night}" + result = f"- {city}: {weather}\n - ️️️️🌡️ 最高気温: {max_temp} ℃\n - ☔ 朝: {chanceOfRain_morning} | 昼: {chanceOfRain_evening} | 晩: {chanceOfRain_night}" return result From cd9bb08034a80a2cfccbd4bbd3f7782ca37b1d6e Mon Sep 17 00:00:00 2001 From: quojama Date: Sun, 12 May 2024 05:11:03 +0900 Subject: [PATCH 2/2] rye check pass --- src/libs/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/utils.py b/src/libs/utils.py index 4f25e12..2d398d2 100644 --- a/src/libs/utils.py +++ b/src/libs/utils.py @@ -62,7 +62,7 @@ def get_weather(citycode: str): chanceOfRain_evening = json["forecasts"][0]["chanceOfRain"]["T12_18"] chanceOfRain_night = json["forecasts"][0]["chanceOfRain"]["T18_24"] - result = f"- {city}: {weather}\n - ️️️️🌡️ 最高気温: {max_temp} ℃\n - ☔ 朝: {chanceOfRain_morning} | 昼: {chanceOfRain_evening} | 晩: {chanceOfRain_night}" + result = f"- {city}: {weather}\n - ️️️️🌡️ 最高気温: {max_temp} ℃\n - ☔ 朝: {chanceOfRain_morning} | 昼: {chanceOfRain_evening} | 晩: {chanceOfRain_night}" # noqa: E501 return result