Created
February 19, 2021 11:33
-
-
Save kotoripiyopiyo/53427fc2596381402a64360e74612253 to your computer and use it in GitHub Desktop.
天気取得Ver2.0
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
#!/usr/bin/rnv python3 | |
# quickWeather 東京と那須と逗子の天気を表示 54行 | |
import json | |
import requests | |
# city番号をリストに。東京、逗子(横浜)、那須(太田原) | |
cities = ['130010', '140010', '090020'] | |
for i in range(len(cities)): | |
# https://weather.tsukumijima.net/api/forecast のAPIからJSONデータをダウンロードする | |
response_city = requests.get('https://weather.tsukumijima.net/api/forecast/city/' + cities[i]) | |
response_city.raise_for_status | |
# JSONデータからPython変数に読み込む | |
weather_data = json.loads(response_city.text) | |
print(weather_data['title']) | |
w = weather_data['forecasts'] | |
# 今日(2021-02-14):晴れ みたいな形式 | |
for j in range(3): | |
print(f'{w[j]["dateLabel"]}({w[j]["date"]}):{w[j]["telop"]}') | |
print('-----') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
前よりコードの量を半分にした