DAHITI-API with Python

This is the new BETA version of the DAHITI-API which is still in testing phase.
If you have any problems or questions using the DAHITI-API do not hesitate to contact the DAHITI-Team.

list-targets

List selected targets from the DAHITI data holding

import requests
import json

url = 'http://dahiti.dgfi.tum.de/api/v1/'

args = {}
""" required options """
args['username'] = 'username'
args['password'] = 'password'
args['action'] = 'list-targets'

""" optional options """
#args['basin'] = 'Amazon'
#args['continent'] = 'Asia'
#args['country'] = 'de'
#args['min_lon'] = 0
#args['max_lon'] = 10
#args['min_lat'] = 0
#args['max_lat'] = 10
#args['software'] = '3.1'

""" send request as method POST """
response = requests.post(url, data=args)
""" send request as method GET """
response = requests.get(url, params=args)

if response.status_code == 200:
	""" convert json string in python list """
	data = json.loads(response.text)
	for record in data:
		print record
else:
	print response.status_code


target-info

Get information of selected DAHITI target

import requests
import json

url = 'http://dahiti.dgfi.tum.de/api/v1/'

args = {}
""" required options """
args['username'] = 'username'
args['password'] = 'password'
args['action'] = 'target-info'
args['dahiti_id'] = '85'

""" send request as method POST """
response = requests.post(url, data=args)
""" send request as method GET """
response = requests.get(url, params=args)

if response.status_code == 200:
	""" convert json string in python dictionary """
	data = json.loads(response.text)
	keys = data.keys()
	for key in keys:
		print key,':',data[key]
else:
	print response.status_code


download

Download of a DAHITI water level time series

import requests
import json

url = 'http://dahiti.dgfi.tum.de/api/v1/'

args = {}
""" required options """
args['username'] = 'username'
args['password'] = 'password'
args['action'] = 'download'
args['dahiti_id'] = '85'

""" send request as method POST """
response = requests.post(url, data=args)
""" send request as method GET """
response = requests.get(url, params=args)

if response.status_code == 200:
	""" convert json string in python list """
	data = json.loads(response.text)
	for record in data:
		print record
else:
	print response.status_code