View difference between Paste ID: Yr73iB3V and xQtZAQwU
SHOW: | | - or go back to the newest paste.
1
import output
2
import requests
3
import json
4
5
class Xively(output.Output):
6
	proxies = {
7
		"http": "http://10.10.1.10:3128",
8
		"https": "http://10.10.1.10:1080"
9
	}
10
	requiredData = ["APIKey","FeedID"]
11
	optionalData = []
12
	def __init__(self,data):
13
		self.APIKey=data["APIKey"]
14
		self.FeedID=data["FeedID"]
15
	def outputData(self,dataPoints):
16
		arr = []
17
		for i in dataPoints:
18
			arr.append({"id":i["name"],"current_value":i["value"]})
19
		a = json.dumps({"version":"1.0.0","datastreams":arr})
20
		try:
21-
			z = requests.put("http://api.xively.com/v2/feeds/"+self.FeedID+".json",headers={"X-ApiKey":self.APIKey},data=a, proxies=proxies)
21+
			z = requests.put("http://api.xively.com/v2/feeds/"+self.FeedID+".json",headers={"X-ApiKey":self.APIKey},data=a, proxies=self.proxies)
22
			if z.text!="": 
23
				print "Xively Error: " + z.text
24
				return False
25
		except Exception:
26
			return False
27
		return True