Created
February 20, 2017 10:59
-
-
Save MitI-7/3c799a22958cd05e1186601525fc7525 to your computer and use it in GitHub Desktop.
天気予報の取得
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
import json | |
import urllib.request | |
def main(): | |
jsonp = urllib.request.urlopen("http://www.drk7.jp/weather/json/13.js").read().decode("utf-8") | |
data = json.loads(jsonp.replace("drk7jpweather.callback(", "")[:-2]) | |
for j in data["pref"]["area"]["東京地方"]["info"]: | |
date = j["date"] | |
rainfall_chance = j["rainfallchance"] | |
temperature = j["temperature"] | |
weather = j["weather"] | |
max_temp, min_temp = temperature["range"] | |
print("{0}".format(date)) | |
print("気温:{0}℃ - {1}℃".format(min_temp["content"], max_temp["content"])) | |
print("天気:{0}".format(weather)) | |
print("降水確率") | |
for k in rainfall_chance["period"]: | |
print(" {0}:{1}%".format(k["hour"], k["content"])) | |
print() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment