Configuration

The WeatherDB module has several configurations you can make. Those are stored in a INI-File.

create user configuration

To configure your WeatherDB module, you need to create a user configuration file somewhere on your system. To do so:

import weatherdb as wdb
wdb.config.create_user_config()
weatherdb create-user-config

This now created a INI-File with all possible configurations, but all values are commented out and you will see the default value. After creating the file, you can edit the configuration file with any Texteditor and WeatherDB will use those configurations on your next import.

Setup database

To get started you need to setup your PostGreSQL database the WeatherDB module should use.

There are two usage scenarios:

  1. your working with an existing WeatherDB-database someone else did setup. Then continue with this guide

  2. you want to create your own WeatherDB database instance. Then first follow the hosting instructions.

setup main connection

To setup you database connection open the previously created user configuration file find the [database:main] section and uncomment the options and fill them out with your credentials:

[database:main]
; setup a database connection
; The password should not be stored in the config file, as it is a security risk.
; the module will ask for the password on first execution and store it in the keyring.
HOST = localhost
PORT = 5432
DATABASE = weatherdb
USER = weatherdb

To set your password you will just have to use the module for the first time and will then get prompted to enter the password. This password is then securely stored in your keyring.

Warning

Don’t add a setting for your password in the ini file as this would be a security risk.

Tip

If you use the database at the hydrology department of Freiburg, please go to the apps.hydro.intra.uni-freiburg.de/weatherdb. There you can create yourself an account and download your login credentials from your profile page (“API Password”).

example

For example for the user philip, who’s using the UNI Freiburg internal database weatherdb on host fuhys017.public.ads.uni-freiburg.de with port 5432 this part will look like:

[database:main]
; setup a database connection
; The password should not be stored in the config file, as it is a security risk.
; the module will ask for the password on first execution and store it in the keyring.
HOST = fuhys017.public.ads.uni-freiburg.de
PORT = 5432
DATABASE = weatherdb
USER = philip

multiple connections

The WeatherDB configuration also allows you to work with multiple database connections. This works similarly as with the main database, but you don’t use the [connection:main] section of the configuration file, but add a custom connection subsection by giving it any name of your choice [connection:my_con_name].

Then you have to tell WeatherDB to use this connection:

import weatherdb as wdb

wdb.config.set("database", "connection", "my_con_name")

Alternatively you can also set this custom database connection to be used as the default connection. To do so look for the [connection:main] section in the user configuration file and change the connection= value to your my_con_name:

[database]
; These are the main database settings
; The database is created with the cli command create-db-schema or the weatherdb.Broker().create_db_schema() method
; you can define multiple database connections by adding a new section like [database.connection_name], where you can define your connection name
; The connection setting defines which connection is used if not specified
connection = my_con_name

Example

[database]
connection = my_con_name

[database:my_con_name]
HOST = fuhys017.public.ads.uni-freiburg.de
PORT = 5432
DATABASE = weatherdb
USER = ada

Attention

make sure to replace my_con_name with your chosen name in every statement.