【Python】PythonでAPIを叩く

import requests
import json

url = 'https://api.aoikujira.com/tenki/week.php?fmt=json'
res = requests.get(url)
data = res.json()

print(json.dumps(data, indent=2))

以下のように出力される。

{
  "mkdate": "2021/06/29 23:01:09",
  "\u91e7\u8def": [
    {
      "date": "30\u65e5(\u6c34)",
      "forecast": "\u66c7",
      "mintemp": "-",
      "maxtemp": "-",
      "pop": "-"
    },
    {
      "date": "01\u65e5(\u6728)",
      "forecast": "\u66c7",
      "mintemp": "12",
      "maxtemp": "17",
      "pop": "10"
    },
    {
      "date": "02\u65e5(\u91d1)",
      "forecast": "\u66c7\u6642\u3005\u6674",
      "mintemp": "12",
      "maxtemp": "18",
      "pop": "10"
    },
    {
      "date": "03\u65e5(\u571f)",
      "forecast": "\u66c7",
      "mintemp": "12",
      "maxtemp": "18",
      "pop": "20"
    },
    {
      "date": "04\u65e5(\u65e5)",
      "forecast": "\u66c7",
      "mintemp": "12",
      "maxtemp": "19",
      "pop": "20"
    },
    {
      "date": "05\u65e5(\u6708)",
      "forecast": "\u66c7",
      "mintemp": "12",
      "maxtemp": "18",
      "pop": "30"
    },
    {
      "date": "06\u65e5(\u706b)",
      "forecast": "\u66c7",
      "mintemp": "14",
      "maxtemp": "19",
      "pop": "40"
    }
  ],

  (中略)

  "\u77f3\u57a3": [
    {
      "date": "30\u65e5(\u6c34)",
      "forecast": "\u6674\u6642\u3005\u66c7",
      "mintemp": "-",
      "maxtemp": "-",
      "pop": "-"
    },
    {
      "date": "01\u65e5(\u6728)",
      "forecast": "\u66c7\u6642\u3005\u6674",
      "mintemp": "29",
      "maxtemp": "33",
      "pop": "20"
    },
    {
      "date": "02\u65e5(\u91d1)",
      "forecast": "\u6674\u6642\u3005\u66c7",
      "mintemp": "29",
      "maxtemp": "33",
      "pop": "10"
    },
    {
      "date": "03\u65e5(\u571f)",
      "forecast": "\u6674\u6642\u3005\u66c7",
      "mintemp": "29",
      "maxtemp": "33",
      "pop": "10"
    },
    {
      "date": "04\u65e5(\u65e5)",
      "forecast": "\u6674\u6642\u3005\u66c7",
      "mintemp": "29",
      "maxtemp": "33",
      "pop": "10"
    },
    {
      "date": "05\u65e5(\u6708)",
      "forecast": "\u6674\u6642\u3005\u66c7",
      "mintemp": "28",
      "maxtemp": "33",
      "pop": "10"
    },
    {
      "date": "06\u65e5(\u706b)",
      "forecast": "\u6674\u6642\u3005\u66c7",
      "mintemp": "29",
      "maxtemp": "32",
      "pop": "10"
    }
  ]
}

参考

クジラWeb API - tenki
タイトルとURLをコピーしました