Skip to content

Instantly share code, notes, and snippets.

@lukecampbell
Created December 13, 2016 18:20
Show Gist options
  • Save lukecampbell/0ce0bba5a6ca5f1e619d42ce8890e733 to your computer and use it in GitHub Desktop.
Save lukecampbell/0ce0bba5a6ca5f1e619d42ce8890e733 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import requests"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"response = requests.get('https://dev-catalog.ioos.us/api/3/action/resource_search?query=format:SOS')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"data = response.json()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{u'cache_last_updated': None,\n",
" u'cache_url': None,\n",
" u'created': u'2016-12-09T14:43:16.884750',\n",
" u'description': u'DescribeSensor URL for station urn:ioos:station:NOAA.NOS.CO-OPS:lc0101 station, Calcasieu Channel LB 36',\n",
" u'format': u'SOS',\n",
" u'hash': u'',\n",
" u'id': u'7cfa5746-e165-4e5c-9e14-5121af5bc29c',\n",
" u'last_modified': None,\n",
" u'mimetype': None,\n",
" u'mimetype_inner': None,\n",
" u'name': u'DescribeSensor - Station: lc0101',\n",
" u'package_id': u'0006f46c-e293-45a6-af94-481c3e9022af',\n",
" u'position': 0,\n",
" u'resource_locator_function': u'download',\n",
" u'resource_locator_protocol': u'OGC:SOS:DescribeSensor',\n",
" u'resource_type': None,\n",
" u'revision_id': u'7f82b172-1931-4151-ab96-99c67335e2d0',\n",
" u'size': None,\n",
" u'state': u'active',\n",
" u'url': u'https://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/SOS?request=DescribeSensor&service=SOS&outputFormat=text/xml; subtype=\"sensorML/1.0.1/profiles/ioos_sos/1.0\"&version=1.0.0&procedure=urn:ioos:station:NOAA.NOS.CO-OPS:lc0101',\n",
" u'url_type': None}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data['result']['results'][0]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def get_resource_organization(resource):\n",
" url = 'https://dev-catalog.ioos.us/api/3/action/package_show?id={}'.format(resource['package_id'])\n",
" response = requests.get(url)\n",
" if response.status_code != 200:\n",
" raise IOError(\"Failed to get package {}\".format(resource['package_id']))\n",
" package = response.json()['result']\n",
" return package['organization']"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{u'approval_status': u'approved',\n",
" u'created': u'2016-07-13T17:04:33.714292',\n",
" u'description': u'NOAA National Ocean Service CO-OPS',\n",
" u'id': u'ff022960-17f4-4991-a14d-ca69a07dbad4',\n",
" u'image_url': u'http://catalog.ioos.us/static/img/np/NOAA-Transparent-Logo.png',\n",
" u'is_organization': True,\n",
" u'name': u'nos',\n",
" u'revision_id': u'9ac24744-bb08-48be-8e91-9a256dc34ee8',\n",
" u'state': u'active',\n",
" u'title': u'NOAA CO-OPS',\n",
" u'type': u'organization'}"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"organization = get_resource_organization(data['result']['results'][0])\n",
"organization"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data provider is NOAA CO-OPS\n"
]
}
],
"source": [
"print \"Data provider is\", organization['title']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment