Importing python library - the wrong way?

The last commit in the Python registry you linked is titled ‘drop Python 2 support’, so you might not have much luck.
But, really, it looks like the API is pretty simple to wrap. Try this out:

class AmbientWeatherClient(object):
	def __init__(self, applicationKey, apiKey):
		self.baseUrl = "https://api.ambientweather.net/v1/"
		self.authorization = {
			"applicationKey": applicationKey,
			"apiKey": apiKey
		}	
		self.client = system.net.httpClient()
		
	def call(self, endpoint, **kwargs):
		kwargs.update(self.authorization)
		response = self.client.get(self.baseUrl + endpoint, params=kwargs)
		return response.json

	def get_devices(self):
		# https://api.ambientweather.net/v1/devices?applicationKey=&apiKey=
		return self.call("devices")

	def get_data(self, macAddress, endDate=None, limit=None):
		# https://api.ambientweather.net/v1/devices/macAddress?apiKey=&applicationKey=&endDate=&limit=288
		kwargs = {"macAddress": macAddress}
		if endDate is not None:
			kwargs["endDate"] = endDate
		if limit is not None:
			kwargs["limit"] = limit
		return self.call("devices", **kwargs)
		
client = AmbientWeatherClient("yourApplicationKey", "yourApiKey")

print client.get_devices()

print client.get_data("yourDeviceMacAddress")
1 Like