Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
天気取得Ver2.0
#!/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('-----')
@kotoripiyopiyo

This comment has been minimized.

Copy link
Owner Author

@kotoripiyopiyo kotoripiyopiyo commented Feb 19, 2021

前よりコードの量を半分にした

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment