mesowx / MesoPy

A Python wrapper for the MesoWest environmental data API
MIT License
59 stars 23 forks source link

Use requests to make RESTful api calls #4

Closed lesserwhirls closed 9 years ago

lesserwhirls commented 9 years ago

Replace code like this:

latest_url = 'nearesttime?&' + 'stid=' + stid + '&' + '&'.join(['%s=%s' % (key, value) for (key, value) in kwargs.items()]) + '&token=' + token

with the built-in Requests support for using dictionaires, and allow Requests to build the request string.

Example from Requests doc:

payload = {'key1': 'value1', 'key2[]': ['value2', 'value3']}
r = requests.get("http://httpbin.org/get", params=payload)
print(r.url)

http://httpbin.org/get?key1=value1&key2%5B%5D=value2&key2%5B%5D=value3
ghost commented 9 years ago

Thanks for your help today and the walkthrough. Code was replaced in commit 3a413f4