Skip to content

Instantly share code, notes, and snippets.

@MitI-7
Created February 20, 2017 10:59
Show Gist options
  • Save MitI-7/3c799a22958cd05e1186601525fc7525 to your computer and use it in GitHub Desktop.
Save MitI-7/3c799a22958cd05e1186601525fc7525 to your computer and use it in GitHub Desktop.
天気予報の取得
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