Skip to content

Municipal data

How to call the data

In your browser

Simply type https://covid19data.dk/mundata in your browser and the API will deliver the data as jsonto your browser. You can then save the data to disk by simply using cntr/cmd + s.

Using R

In R you can leverage the jsonlitepackage and call the api with a few lines of code:

library(jsonlite)

url <- "https://covid19data.dk/mundata"
df  <-  fromJSON(url)

Using Python

In Python you can use the requests and the pandas libraries to read in the data:

import requests
import pandas as pd

url = 'https://covid19data.dk/mundata'

resp = requests.get(url)
jsondata = resp.json()

pd.DataFrame(jsondata)

Source of the data

The source of the data are the zipped CSV files distributed from SSI on their website.

As long as they keep coming in the format they do now, the API will ingest them and make them ready for you to use.

Data collection

I have built a few functions in Python that read the html of the the above mentioned SSI website and then looks for new zipfiles and downloads them. After that I extract the municipal data from the files.

SSI provides a bunch of "snapshots" - meaning the status on the current day. I join all the snapshots together in one data set.

This joined data is then saved to a local file on the API server. Everytime there is a request to the API, then the code checks to see how old the file on disk is, and if it is older than 60 minutes, then API looks at SSI to see if there is new data. If this is the case, then the new data gets scrabed and stored.

It is the above mentioned local file that is served when the API is called.