Last active
July 9, 2018 19:19
-
-
Save greencoder/f2b80e01b964b96e0d79a9648099c15d to your computer and use it in GitHub Desktop.
Fetches the mean average temperature and the mean observed average temperature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body = { | |
'sid': 'DENthr', | |
'sdate': '2018-01-01', | |
'edate': '2018-06-31', | |
'output': 'json', # csv or json | |
'elems': [ | |
{ | |
"name": "avgt", | |
"interval": "mly", | |
"duration": "mly", | |
"reduce": "mean", | |
"normal": "departure" | |
}, | |
{ | |
"name": "avgt", | |
"interval": "mly", | |
"duration": "mly", | |
"reduce": "mean", | |
"normal": "1" | |
}, | |
] | |
} | |
# Use your standard URLEncode stuff here | |
encoded_body = json.dumps(body) | |
url = 'http://data.rcc-acis.org/StnData' | |
body = {'params': encoded_body} | |
# Be aware that the requests library automatically URL encodes the | |
# value of the data parameter, so you might have to play with this | |
# to get it working the way you want. The really nasty part about this | |
# API is that you have to URL encode the value of your "params" first, | |
# then it gets encoded again as the post body | |
request = requests.post(url, data=body) | |
response = request.text | |
print(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl 'https://data.rcc-acis.org/StnData' \ | |
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \ | |
-H 'Accept: application/json, text/javascript, */*; q=0.01' \ | |
--data 'output=json¶ms=%7B%22sid%22%3A%22DENthr%22%2C%22sdate%22%3A%222018-01-01%22%2C%22edate%22%3A%222018-06-30%22%2C%22elems%22%3A%5B%7B%22name%22%3A%22avgt%22%2C%22interval%22%3A%22mly%22%2C%22reduce%22%3A%22mean%22%2C%22normal%22%3A%22departure%22%7D%2C%7B%22name%22%3A%22avgt%22%2C%22interval%22%3A%22mly%22%2C%22reduce%22%3A%22mean%22%2C%22normal%22%3A%221%22%7D%5D%7D' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"meta":{ | |
"state": "CO", | |
"sids": ["DENthr 9"], | |
"uid": 32706, | |
"name": "Denver Area" | |
}, | |
"data":[ | |
["2018-01","3.95","30.70"], | |
["2018-02","-2.61","32.50"], | |
["2018-03","2.28","40.40"], | |
["2018-04","0.42","47.40"], | |
["2018-05","4.34","57.10"], | |
["2018-06","5.03","67.40"] | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added the bash script to cURL it, but be aware it requires URL encoding on the JSON you supply as the argument to the
params
parameter.