-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from jphacks/feature/calendar_with_weather
Feature/calendar with weather
- Loading branch information
Showing
8 changed files
with
141 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""empty message | ||
Revision ID: 0ea1059c8f7c | ||
Revises: 8bd32b7bb552 | ||
Create Date: 2023-11-18 21:52:58.786979 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "0ea1059c8f7c" | ||
down_revision: Union[str, None] = "8bd32b7bb552" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column("session", sa.Column("created_at", sa.DateTime(), nullable=False)) | ||
op.add_column("session", sa.Column("weather_code", sa.Integer(), nullable=False)) | ||
op.add_column("user", sa.Column("ido_longitude", sa.Float(), nullable=False)) | ||
op.add_column("user", sa.Column("keido_latitude", sa.Float(), nullable=False)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("user", "keido_latitude") | ||
op.drop_column("user", "ido_longitude") | ||
op.drop_column("session", "weather_code") | ||
op.drop_column("session", "created_at") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import requests | ||
|
||
|
||
def get_weather_code(ido_longitude: float, keido_latitude: float) -> int: | ||
url: str = ( | ||
f"https://api.open-meteo.com/v1/forecast?latitude={ido_longitude}&longitude={keido_latitude}" | ||
"&timezone=Asia%2FTokyo&forecast_days¤t=weather_code" | ||
) | ||
|
||
try: | ||
r = requests.get(url).json() | ||
return r.get("daily").get("weather_code") | ||
except Exception: | ||
# 困ったら曇り | ||
return 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
def weather_code2icon(weather_code: int) -> str: | ||
""" | ||
WMO 天気コードを4分類にする | ||
https://open-meteo.com/en/docs | ||
https://www.jodc.go.jp/data_format/weather-code_j.html#:~:text=%E7%8F%BE%E5%9C%A8%E5%A4%A9%E5%80%99(Present%20Weather)%20(WMO%20Code%204677) | ||
""" | ||
if weather_code in ["0", "1"]: | ||
# 晴れ | ||
return "☀" | ||
|
||
elif weather_code in ["2", "3"]: | ||
# 曇り | ||
return "☁" | ||
|
||
elif weather_code in [ | ||
# 雨 | ||
"45", | ||
"48", | ||
"51", | ||
"53", | ||
"55", | ||
"56", | ||
"57", | ||
"61", | ||
"63", | ||
"65", | ||
"66", | ||
"67", | ||
"80", | ||
"81", | ||
"82", | ||
"95", | ||
"96", | ||
"99", | ||
]: | ||
return "🌧" | ||
|
||
elif weather_code in ["71", "73", "75", "77", "85", "86"]: | ||
# 雪 | ||
return "🌨" | ||
|
||
# その他 | ||
else: | ||
# その他,曇りとする | ||
return "☁" |