Skip to content

Instantly share code, notes, and snippets.

@lsetiawan
Created August 18, 2017 20:28
Show Gist options
  • Save lsetiawan/5450e69df1a5257545aec2c29c8696d3 to your computer and use it in GitHub Desktop.
Save lsetiawan/5450e69df1a5257545aec2c29c8696d3 to your computer and use it in GitHub Desktop.
This is WOFpy Client SOAP and REST Test with `ulmo`.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pytz\n",
"import pandas as pd\n",
"\n",
"import io\n",
"\n",
"from suds.client import Client\n",
"import isodate\n",
"\n",
"import ulmo\n",
"import requests\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" ulmo.cuahsi.wof\n",
" ~~~~~~~~~~~~~~~\n",
"\n",
" `CUAHSI WaterOneFlow`_ web services\n",
"\n",
" .. _CUAHSI WaterOneFlow: http://his.cuahsi.org/wofws.html\n",
"\n"
]
}
],
"source": [
"print(ulmo.cuahsi.wof.__doc__)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['absolute_import', 'core', 'get_site_info', 'get_sites', 'get_values', 'get_variable_info']\n"
]
}
],
"source": [
"print([obj for obj in dir(ulmo.cuahsi.wof) if not obj.startswith('__')])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## SOAP 1.1 Testing"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"postgresurl, mysqlurl = 'http://54.186.36.247:8080/postgresqlodm2timeseries/soap/cuahsi_1_1/.wsdl', 'http://54.186.36.247:8080/mysqlodm2timeseries/soap/cuahsi_1_1/.wsdl'"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"wsdl_urls = [postgresurl, mysqlurl]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--------------------------\n",
"Testing http://54.186.36.247:8080/postgresqlodm2timeseries/soap/cuahsi_1_1/.wsdl\n",
"--------------------------\n",
"SITES-----------------\n",
"GetSites failed!\n",
"SITE INFO postgresqlodm2timeseries:160065_4vars-------------\n",
"GetSiteInfo failed!\n",
"VARIABLES-------------\n",
"['postgresqlodm2timeseries:EnviroDIY_Mayfly_Volt', 'postgresqlodm2timeseries:Adafruit_DS18B20_Temp', 'postgresqlodm2timeseries:Decagon_ES-2_EC', 'postgresqlodm2timeseries:Adafruit_AM2315_humidity', 'postgresqlodm2timeseries:Decagon_CTD-10_Depth', 'postgresqlodm2timeseries:Decagon_5TM_VWC', 'postgresqlodm2timeseries:Adafruit_AM2315_Temp', 'postgresqlodm2timeseries:Campbell_OBS-3+_Turb', 'postgresqlodm2timeseries:EnviroDIY_Mayfly_FreeSRAM', 'postgresqlodm2timeseries:EnviroDIY_Mayfly_Temp', 'postgresqlodm2timeseries:Decagon_5TM_Ea', 'postgresqlodm2timeseries:Decagon_CTD-10_Temp', 'postgresqlodm2timeseries:Decagon_CTD-10_EC', 'postgresqlodm2timeseries:Seeed_BME280_Temp', 'postgresqlodm2timeseries:Seeed_BME280_humidity', 'postgresqlodm2timeseries:Decagon_ES-2_Temp', 'postgresqlodm2timeseries:Decagon_5TM_Temp', 'postgresqlodm2timeseries:MaxBotix_MB7386_Distance']\n",
"VARIABLE INFO postgresqlodm2timeseries:EnviroDIY_Mayfly_Temp-------------\n",
"Temperature\n",
"VALUES----------------\n",
"11\n",
"--------------------------\n",
"Testing http://54.186.36.247:8080/mysqlodm2timeseries/soap/cuahsi_1_1/.wsdl\n",
"--------------------------\n",
"SITES-----------------\n",
"['mysqlodm2timeseries:USU-LBR-Mendon', 'mysqlodm2timeseries:USU-LBR-SFWeather']\n",
"SITE INFO mysqlodm2timeseries:USU-LBR-Mendon-------------\n",
"{'site_comments': 'Located below county road bridge at Mendon Road crossing'}\n",
"VARIABLES-------------\n",
"['mysqlodm2timeseries:USU57', 'mysqlodm2timeseries:USU56', 'mysqlodm2timeseries:USU55', 'mysqlodm2timeseries:USU54', 'mysqlodm2timeseries:USU53', 'mysqlodm2timeseries:USU52', 'mysqlodm2timeseries:USU51', 'mysqlodm2timeseries:USU47', 'mysqlodm2timeseries:USU59', 'mysqlodm2timeseries:USU58', 'mysqlodm2timeseries:USU13', 'mysqlodm2timeseries:USU10', 'mysqlodm2timeseries:USU17', 'mysqlodm2timeseries:USU16', 'mysqlodm2timeseries:USU15', 'mysqlodm2timeseries:USU14', 'mysqlodm2timeseries:USU35', 'mysqlodm2timeseries:USU34', 'mysqlodm2timeseries:USU37', 'mysqlodm2timeseries:USU36', 'mysqlodm2timeseries:USU31', 'mysqlodm2timeseries:USU30', 'mysqlodm2timeseries:USU33', 'mysqlodm2timeseries:USU32', 'mysqlodm2timeseries:USU7', 'mysqlodm2timeseries:USU6', 'mysqlodm2timeseries:USU5', 'mysqlodm2timeseries:USU4', 'mysqlodm2timeseries:USU3', 'mysqlodm2timeseries:USU9', 'mysqlodm2timeseries:USU8', 'mysqlodm2timeseries:USU19', 'mysqlodm2timeseries:USU62', 'mysqlodm2timeseries:USU60', 'mysqlodm2timeseries:USU61', 'mysqlodm2timeseries:USU18', 'mysqlodm2timeseries:USU44', 'mysqlodm2timeseries:USU50', 'mysqlodm2timeseries:USU48', 'mysqlodm2timeseries:USU49', 'mysqlodm2timeseries:USU28', 'mysqlodm2timeseries:USU29', 'mysqlodm2timeseries:USU26', 'mysqlodm2timeseries:USU27', 'mysqlodm2timeseries:USU24', 'mysqlodm2timeseries:USU25', 'mysqlodm2timeseries:USU22', 'mysqlodm2timeseries:USU23', 'mysqlodm2timeseries:USU20', 'mysqlodm2timeseries:USU21']\n",
"VARIABLE INFO mysqlodm2timeseries:USU36-------------\n",
"Temperature\n",
"VALUES----------------\n",
"1440\n"
]
}
],
"source": [
"for url in wsdl_urls:\n",
" print('--------------------------')\n",
" print('Testing {}'.format(url))\n",
" print('--------------------------')\n",
" \n",
" networkcode = url.split('/')[3]\n",
" if 'postgres' in networkcode:\n",
" sitecode = '{netcode}:160065_4vars'.format(netcode=networkcode)\n",
" variablecode = '{netcode}:EnviroDIY_Mayfly_Temp'.format(netcode=networkcode)\n",
" elif 'mysql' in networkcode:\n",
" sitecode = '{netcode}:USU-LBR-Mendon'.format(netcode=networkcode)\n",
" variablecode = '{netcode}:USU36'.format(netcode=networkcode)\n",
" \n",
" print('SITES-----------------')\n",
" try:\n",
" sites = ulmo.cuahsi.wof.get_sites(url)\n",
" \n",
" print(sites.keys())\n",
" except:\n",
" print('GetSites failed!')\n",
" \n",
" print('SITE INFO {}-------------'.format(sitecode))\n",
" try:\n",
" siteinfo = ulmo.cuahsi.wof.get_site_info(url, site_code=sitecode)\n",
" \n",
" print(siteinfo['site_property'])\n",
" except:\n",
" print('GetSiteInfo failed!')\n",
" \n",
" print('VARIABLES-------------')\n",
" try:\n",
" variables = ulmo.cuahsi.wof.get_variable_info(url)\n",
" \n",
" print(variables.keys())\n",
" except:\n",
" print('GetVariables failed!')\n",
"\n",
" print('VARIABLE INFO {}-------------'.format(variablecode))\n",
" try:\n",
" variable = ulmo.cuahsi.wof.get_variable_info(url, variable_code=variablecode)\n",
" \n",
" print(variable['name'])\n",
" except:\n",
" print('GetVariableInfo failed!')\n",
" \n",
" \n",
" print('VALUES----------------') \n",
" try:\n",
" values = ulmo.cuahsi.wof.get_values(url, site_code=sitecode, variable_code=variablecode)\n",
" \n",
" print(len(values['values']))\n",
" except:\n",
" print('GetValues failed!')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## REST 1.1 Testing"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"resturls = ['http://54.186.36.247:8080/postgresqlodm2timeseries/rest/1_1',\n",
" 'http://54.186.36.247:8080/mysqlodm2timeseries/rest/1_1']"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--------------------------\n",
"Testing http://54.186.36.247:8080/postgresqlodm2timeseries/rest/1_1\n",
"--------------------------\n",
"SITES-----------------\n",
"GetSites failed!\n",
"SITE INFO postgresqlodm2timeseries:160065_4vars-------------\n",
"GetSiteInfo failed!\n",
"VARIABLES-------------\n",
"['Decagon_CTD-10_Temp', 'Decagon_5TM_Temp', 'EnviroDIY_Mayfly_Temp', 'Adafruit_AM2315_Temp', 'EnviroDIY_Mayfly_Volt', 'Decagon_CTD-10_EC', 'Decagon_5TM_Ea', 'Seeed_BME280_Temp', 'Campbell_OBS-3+_Turb', 'Decagon_ES-2_EC', 'Decagon_CTD-10_Depth', 'Decagon_5TM_VWC', 'Decagon_ES-2_Temp', 'MaxBotix_MB7386_Distance', 'Adafruit_AM2315_humidity', 'EnviroDIY_Mayfly_FreeSRAM', 'Seeed_BME280_humidity', 'Adafruit_DS18B20_Temp']\n",
"VARIABLE INFO postgresqlodm2timeseries:EnviroDIY_Mayfly_Temp-------------\n",
"GetVariableInfo failed!\n",
"VALUES----------------\n",
"GetValues failed!\n",
"--------------------------\n",
"Testing http://54.186.36.247:8080/mysqlodm2timeseries/rest/1_1\n",
"--------------------------\n",
"SITES-----------------\n",
"['USU-LBR-Mendon', 'USU-LBR-SFWeather']\n",
"SITE INFO mysqlodm2timeseries:USU-LBR-Mendon-------------\n",
"GetSiteInfo failed!\n",
"VARIABLES-------------\n",
"['USU36', 'USU35', 'USU44', 'USU47', 'USU48', 'USU49', 'USU30', 'USU26', 'USU27', 'USU24', 'USU25', 'USU22', 'USU23', 'USU20', 'USU21', 'USU62', 'USU31', 'USU60', 'USU61', 'USU28', 'USU29', 'USU7', 'USU6', 'USU5', 'USU4', 'USU3', 'USU33', 'USU32', 'USU9', 'USU8', 'USU57', 'USU56', 'USU55', 'USU54', 'USU53', 'USU52', 'USU51', 'USU50', 'USU59', 'USU58', 'USU13', 'USU34', 'USU37', 'USU10', 'USU17', 'USU16', 'USU15', 'USU14', 'USU19', 'USU18']\n",
"VARIABLE INFO mysqlodm2timeseries:USU36-------------\n",
"GetVariableInfo failed!\n",
"VALUES----------------\n",
"GetValues failed!\n"
]
}
],
"source": [
"for url in resturls:\n",
" print('--------------------------')\n",
" print('Testing {}'.format(url))\n",
" print('--------------------------')\n",
" \n",
" networkcode = url.split('/')[3]\n",
" if 'postgres' in networkcode:\n",
" sitecode = '{netcode}:160065_4vars'.format(netcode=networkcode)\n",
" variablecode = '{netcode}:EnviroDIY_Mayfly_Temp'.format(netcode=networkcode)\n",
" elif 'mysql' in networkcode:\n",
" sitecode = '{netcode}:USU-LBR-Mendon'.format(netcode=networkcode)\n",
" variablecode = '{netcode}:USU36'.format(netcode=networkcode)\n",
" \n",
" print('SITES-----------------')\n",
" try:\n",
" req = requests.get(os.path.join(url, 'GetSites'))\n",
" response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n",
" sites = ulmo.waterml.v1_1.parse_site_infos(response_buffer)\n",
" \n",
" print(sites.keys())\n",
" except:\n",
" print('GetSites failed!')\n",
" \n",
" print('SITE INFO {}-------------'.format(sitecode))\n",
" try:\n",
" req = requests.get(os.path.join(url, 'GetSiteInfo'), params={'site':sitecode})\n",
" response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n",
" siteinfo = ulmo.waterml.v1_1.parse_sites(response_buffer)\n",
" \n",
" print(siteinfo['site_property'])\n",
" except:\n",
" print('GetSiteInfo failed!')\n",
" \n",
" print('VARIABLES-------------')\n",
" try:\n",
" req = requests.get(os.path.join(url, 'GetVariables'))\n",
" response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n",
" variables = ulmo.waterml.v1_1.parse_variables(response_buffer)\n",
" \n",
" print(variables.keys())\n",
" except:\n",
" print('GetVariables failed!')\n",
"\n",
" print('VARIABLE INFO {}-------------'.format(variablecode))\n",
" try:\n",
" req = requests.get(os.path.join(url, 'GetVariableInfo'), params={'variable':variablecode})\n",
" response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n",
" variable = ulmo.waterml.v1_1.parse_variables(response_buffer)\n",
" \n",
" print(variable['name'])\n",
" except:\n",
" print('GetVariableInfo failed!')\n",
" \n",
" \n",
" print('VALUES----------------') \n",
" try:\n",
" req = requests.get(os.path.join(url, 'GetValues'), params={'location':sitecode, \n",
" 'variable':variablecode})\n",
" response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n",
" values = ulmo.waterml.v1_1.parse_site_values(response_buffer)\n",
" \n",
" print(len(values['values']))\n",
" except:\n",
" print('GetValues failed!')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:uwapl_em_mc_1aui]",
"language": "python",
"name": "conda-env-uwapl_em_mc_1aui-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment