@@ -1 +1,2089 @@
 %0A
+# *****************************************************************************%0A# Copyright (c) 2014 IBM Corporation and other Contributors.%0A#%0A# All rights reserved. This program and the accompanying materials%0A# are made available under the terms of the Eclipse Public License v1.0%0A# which accompanies this distribution, and is available at%0A# http://www.eclipse.org/legal/epl-v10.html%0A#%0A# Contributors:%0A#   Lokesh Haralakatta%0A# *****************************************************************************%0A%0A'''%0A    Example of retrieving a list of the first five documents from a database for%0A    the device %22piCam-1%22, applying the view by-deviceId and further process the%0A    device data to get data values for the first five documents%0A'''%0Aimport requests%0A%0A# Define cloudant username%0Auser = %22%3Ccloudant-user%3E%22%0A%0A# Define cloudant password%0Apasswd = %22%3Ccloudant-password%3E%22%0A%0A# Define cloudant host%0Ahost = user+%22.cloudant.com%22%0A%0A# Define cloudant db name%0Adb = %22%3Ccloudant-dbname%3E%22%0A%0A# Define view variable to contain the Map View Name%0Aview = %22by-deviceId%22%0A%0A# Frame the URL using above defned variables values%0Aurl = 'https://'+host+'/'+db+'/_design/iotp/_view/'+view%0A%0A# Define args variable to store required parameter values%0Aargs = %7B 'key'  :  ' %22piCam-1%22 '  ,  'limit'  :  '5'  %7D%0A%0A# Invoke HTTP GET request with all required parameters%0Aresponse = requests.get(url,params=args,auth=(user,passwd))%0A%0A# Check the response status code, should be 200 to proceed further%0Aif ( response.status_code == 200):%0A    # Get the response data in JSON format%0A    jsonData = response.json()%0A    # Get the device data records which are JSON array of rows with in jsonData%0A    records = jsonData%5B'rows'%5D%0A    # For each record, get deviceType, deviceID and devicedata from the records%0A    for record in records:%0A        dType = record%5B'value'%5D%5B'deviceType'%5D%0A        dID = record%5B'value'%5D%5B'deviceId'%5D%0A        dValue = record%5B'value'%5D%5B'data'%5D%5B'd'%5D%5B'value'%5D%0A        print %22Device Type: %25s  Device Id: %25s  Value: %25s%22 %25(dType,dID,str(dValue))%0Aelse:%0A    print %22HTTP GET Failed with Status Code - %25s%22 %25(response.status_code)%0A

Update query-1.py