Skip to content

Commit

Permalink
Merge pull request #228 from pistachiostudio/tendo-weather
Browse files Browse the repository at this point in the history
yamagata weather
  • Loading branch information
quojama authored May 11, 2024
2 parents 0cf6f4c + cd9bb08 commit c85bb39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/cogs/wt_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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が完全に起動してからタスクを回す
Expand Down
8 changes: 4 additions & 4 deletions src/libs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}" # noqa: E501

return result

Expand Down

0 comments on commit c85bb39

Please sign in to comment.