Here we revisit our old NWIS website listing current discharge conditions in the Eno near Durham gage site.
But now we'll examine the URL of this data site as a web service and access it using Python's requests package, which makes data access really quite easy.
This is not actually all that different from the urllib example we reviewed before, but this serves as a nice intro to the requests packages, which is a bit more flexible and powerful than urllib, and also makes coding more "pythonic"
In [ ]:
#import the module
import requests
In [1]:
#dissect the URL into it's components, for easy comprehension -- and easy modification
serviceURL = 'http://waterdata.usgs.gov/nwis/uv'
parameters = {'cb_00060':'on',
'cb_00065':'on',
'format':'rdb',
'period':'1',
'site_no':'02085070',
'begin_date':'',
'end_date':''
}
In [ ]:
#Pass the url and its parameters to the server and get its response
response = requests.get(serviceURL, parameters)
responseText = response.content
In [ ]:
#What did we get?
print(responseText)