def demo(key): client = Client() try: logging.info("Requesting a trigger list") trigger_list = yield client.list_triggers(api_key=key) if trigger_list: logging.info("Success retrieving a trigger list:\n%s\n" % trigger_list) else: logging.error("Problem occurred listing triggers") except Exception, ex: logging.error("Error: %s" % str(ex))
def demo(key, feed_id=None, datastream_id=None, timestamp=None): client = Client() if feed_id and datastream_id: if timestamp: # read the datapoint at the specified timestamp try: logging.info("Reading the datapoint at %s" % timestamp) datapoint = yield client.read_datapoint(api_key=key, feed_id=feed_id, datastream_id=datastream_id, timestamp=timestamp) if datapoint: logging.info("Success reading the datapoint:\n%s\n" % datapoint) else: logging.error("Problem occurred reading the datapoint") except Exception, ex: logging.error("Problem reading the datapoint: %s" % str(ex)) else: # no specific datapoint was requested so just show the last 10 minutes worth # create historical query parameters spanning the last 10 minutes ten_minutes_ago_timestamp = datetime.datetime.utcnow() - datetime.timedelta(minutes=10) start_timestamp = "%sZ" % (ten_minutes_ago_timestamp.isoformat()) parameters = {'start':start_timestamp, 'interval':0} try: logging.info("Requesting to view the last 10 minutes of historical datapoints for datastream %s in feed %s starting from %s" % (datastream_id, feed_id, start_timestamp)) datastream = yield client.read_datastream(api_key=key, feed_id=feed_id, datastream_id=datastream_id, parameters=parameters) if datastream: logging.info("Success retrieving datastream historical datapoints:\n%s\n" % datastream) else: logging.error("Problem reading datastream") except Exception, ex: logging.error("Error reading datastream: %s" % str(ex))
def demo(key, feed_id): client = Client() try: if feed_id: # request feed details for the supplied identifier only logging.info("Requesting feed details for feed: %s" % feed_id) dataStructure = yield client.read_feed(api_key=key, feed_id=feed_id) else: # request feed details for all feeds visible to the key supplied logging.info("Requesting a feed listing") dataStructure = yield client.list_feeds(api_key=key, parameters={'per_page' : 5, 'status' : 'live'}) logging.info("Received response from Pachube:\n%s\n" % dataStructure) reactor.callLater(0.1, reactor.stop) defer.returnValue(True) except Exception, ex: logging.error("Error: %s" % str(ex)) reactor.callLater(0.1, reactor.stop) defer.returnValue(False)
def demo(key, key_id): client = Client() try: if key_id: # request key details for the supplied identifier only logging.info("Requesting key details for key: %s" % key_id) dataStructure = yield client.read_api_key(api_key=key, key_id=key_id) else: # request feed details for all feeds visible to the key supplied logging.info("Requesting a key listing") dataStructure = yield client.list_api_keys(api_key=key) logging.info("Received response from Pachube:\n%s\n" % dataStructure) reactor.callLater(0.1, reactor.stop) defer.returnValue(True) except Exception, ex: logging.error("Error: %s" % str(ex)) reactor.callLater(0.1, reactor.stop) defer.returnValue(False)