Skip to content

Instantly share code, notes, and snippets.

@sowmyagowri
Created October 1, 2017 17:36
Show Gist options
  • Save sowmyagowri/5c4688678dec8294c7f9975fd73ed6a4 to your computer and use it in GitHub Desktop.
Save sowmyagowri/5c4688678dec8294c7f9975fd73ed6a4 to your computer and use it in GitHub Desktop.
Use Airquality data and display the AQI based on the input zipcode. This is done using IBM Data Science Experience
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"metadata": {},
"execution_count": 69,
"outputs": [
{
"name": "stdout",
"text": "The input zipcode 60440 is city Chicago in State IL.\n\nThe Air Quality Index today on 2017-09-27 at 1 hours CST is 34.\n\nThis means the Overall Air Quality is Good.\n",
"output_type": "stream"
}
],
"source": "# importing the requests library\nimport requests\nimport simplejson as json\n\n# api-endpoint\nURL = \"https://airnowapi.org/aq/observation/zipCode/current\"\n\n# input parameters given here\nzipCode=60440\ndistance=10\nreturnFormat='JSON'\napi_key='3253048F-BBBB-4769-9262-E6FBF7E46475'\n \n# defining a params dict for the parameters to be sent to the API\nPARAMS = {'zipCode':zipCode,'distance' :distance, 'format' :returnFormat, 'api_key' :api_key}\n \n# sending get request and saving the response as response object\nresponse = requests.get(url = URL, params = PARAMS)\n\n# extracting data in json format\ndata = response.json()\n\n# printing the output\nprint (\"The input zipcode %d is city %s in State %s.\\n\" %(zipCode, data[0]['ReportingArea'], data[0]['StateCode']))\nprint (\"The Air Quality Index today on %s at %d hours %s is %d.\\n\" %(data[0]['DateObserved'], data[0]['HourObserved'], data[0]['LocalTimeZone'], data[0]['AQI']))\nprint (\"This means the Overall Air Quality is %s.\" %(data[0]['Category']['Name']))"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2 with Spark 2.0",
"name": "python2-spark20",
"language": "python"
},
"language_info": {
"mimetype": "text/x-python",
"name": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11",
"file_extension": ".py",
"codemirror_mode": {
"version": 2,
"name": "ipython"
},
"nbconvert_exporter": "python"
}
},
"nbformat_minor": 1,
"nbformat": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment