Get weatherdata in JSON-format from SMHI (Swedish weather service) Updated 200612

This is an example written in Python to retrieve temperatur data from SMHI and output them to a console.

The temperature data is from Norrköping, Sweden but it is possible to enter any long/lat in Sweden.

The library "requests" must first be imported using this command in a command-window:

Python -m pip install requests

(in my case Python is installed under:  

c:\Program Files (x86)\Python38-32

and here is the code:

import requests
resp = requests.get("https://opendata-download-metfcst.smhi.se/api/category/"+
                    "pmp3g/version/2/geotype/point/lon/16.158/lat/58.5812/data.json")

if resp.status_code != 200:
    # This means something went wrong.
    raise ApiError('GET /tasks/ {}'.format(resp.status_code))

print('temperature. {}'.format(resp.json()["timeSeries"][0]["validTime"]))
print('temperature. {}'.format(resp.json()["timeSeries"][0]["parameters"][11]["values"]))

print(resp.json()["timeSeries"][0]["validTime"])

for timeser in resp.json()["timeSeries"]:
    for param in timeser["parameters"]:
       if param["name"]=="t":
           print('{} {} {}'.format(timeser["validTime"], param["name"], param["values"]))

Figure 1: Output temperature to the console