Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import urllib
- import httplib
- xivelyhost = 'api.xively.com'
- feedurl = '/v2/feeds/1703619548'
- feedid = '170361954'
- apikey = 'EsTjqWQlHyj69kBKBYbtoanldlKxAb7HalVxzW5ef2V5x296' # Read-Only Key
- #
- # Example 1: Pulling JSON Feed from my read-only APIKey URL
- #
- #params = urllib.urlencode({'datastream': 'CO,NO2,Dust,Temperature,Humidity'))
- headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "application/json", "X-ApiKey": apikey}
- http = httplib.HTTPConnection(xivelyhost)
- http.request("GET", feedurl , '', headers)
- response = http.getresponse()
- print(response.status, response.reason)
- eggdata = json.load(response)
- http.close()
- print("Example 1")
- eggdata
- #
- # get to the sensible parts of the data, quick
- #
- datastream_keys = ('CO','Dust','NO2','Temperature','Humidity')
- eggdict = {datastream['id'] : datastream['current_value'] for datastream in eggdata['datastreams'] if (datastream['id'] in datastream_keys)}
- print eggdict
Advertisement
Add Comment
Please, Sign In to add comment