A Windows Download Tool for DESTATIS

2020-06-26 / Destatis / PowerShell / Windows / 2 minutes

The new REST-API released by the German Federal Statistical Office DESTATIS (see my previous blog post) allowed me create a standalone Windows binary (.exe) that allows to easily automate downloads of tidy datasets from the DESTATIS database.

How it works

The tool is very easy to use. To download table 12411-0001 containing aggregate population statistics to a local file destatis-population.csv, you can just run the following line in windows command line:

.\destatis-downloader.exe -table "12411-0001" -file .\destatis-population.csv

The default format is the new “tidy” file format without any custom header lines (except for the column name header), but you can choose the “untidy” or Excel versions as well.

You can run this command on a regular schedule using windows task manager to automate the process.

Setup

  1. Download the executable from the github repo.
  2. Create a json file with your DESTATIS credentials. You can use this template and just input your username and password:
{
    "username": "YOUR_USERNAME",
    "password": "YOUR_PASSWORD"
}

Usage

The script accepts four parameters:

  1. -table: the code for the table you want to download, which has the format “XXXXX-XXXX” in DESTATIS`s GENESIS database. Put the code in double-quotes.
  2. -file (optional): the filename of the output file. The default uses the table code “XXXXX-XXXX.csv” in your current directory.
  3. -cred (optional): the filename of your credentials file. The default assumes “destatis-credentials.json” in your current directory.
  4. -format (optional): the file format of the output file. The default uses the tidy ffcsv format. Other options are csv, datencsv, xlsx and html.

Example

Let’s say you want to download table 12411-0001 in Excel format. Your credentials are in separate folder:`

.\destatis-downloader.exe -table "12411-0001" 
                          -file "C:\Users\flori\OneDrive\Dokumente\data\bevoelkerung.xlsx" 
                          -cred "C:\destatis-credentials.json" 
                          -format "xlsx"

Source Code

The source code is available in github. The PowerShell script has been converted to an .exe using PS2EXE-GUI.