def __init__(self, url, key, env=None, loc=None, dat=list(), use_https=True, timeout=10): """ :param url: the api url either '/v2/feeds/1275.xml' or 1275 :type url: `str` :param key: your personal api key :type key: `str` """ if not env: env = eeml.Environment() if str(url) == url: if(url_pattern.match(url)): self._url = url else: raise ValueError("The url argument has to be in the form " "'/v2/feeds/1275.xml' or 1275") else: try: if int(url) == url: self._url = '/v2/feeds/' + str(url) + '.xml' else: raise TypeError('') except TypeError: raise TypeError("The url argument has to be in the form " "'/v2/feeds/1275.xml' or 1275") self._key = key self._use_https = use_https self._eeml = eeml.create_eeml(env, loc, dat) self._http_timeout = timeout
def __init__(self, url, key, env=None, loc=None, dat=list(), use_https=True, timeout=10): """ :param url: the api url either '/v2/feeds/1275.xml' or 1275 :type url: `str` :param key: your personal api key :type key: `str` """ if not env: env = eeml.Environment() if str(url) == url: if (URLPATTERN.match(url)): self._url = url else: raise ValueError("The url argument has to be in the form " "'/v2/feeds/1275.xml' or 1275") else: try: if int(url) == url: self._url = '/v2/feeds/' + str(url) + '.xml' else: raise TypeError('') except TypeError: raise TypeError("The url argument has to be in the form " "'/v2/feeds/1275.xml' or 1275") self._key = key self._use_https = use_https self._eeml = eeml.create_eeml(env, loc, dat) self._http_timeout = timeout
def __init__(self, url, key): """ :param url: the api url (eg. '/api/1275.xml') :type url: `str` :param key: your personal api key :type key: `str` """ self._url = url self._key = key self._eeml = eeml.create_eeml(eeml.Environment(), None, [])
def test_good_datapoints(self): env = Environment('A Room Somewhere', 'http://www.cosm.com/feeds/1.xml', 'frozen', 'This is a room somewhere', 'http://www.roomsomewhere/icon.png', 'http://www.roomsomewhere/', 'myemail@roomsomewhere', updated=datetime(2007, 5, 4, 18, 13, 51, 0, pytz.utc), creator='http://www.somewhere', id_=1) datapoints = DataPoints( 1, [(0, ), (1, ), (2, datetime(2007, 5, 4, 18, 13, 51, 0, pytz.utc))]) result = create_eeml(env, None, datapoints).toeeml() assert_true( xml_compare(etree.fromstring(""" <eeml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.eeml.org/xsd/0.5.1" xsi:schemaLocation="http://www.eeml.org/xsd/0.5.1 http://www.eeml.org/xsd/0.5.1/0.5.1.xsd" version="0.5.1"> <environment updated="2007-05-04T18:13:51+00:00" creator="http://www.somewhere" id="1"> <title>A Room Somewhere</title> <feed>http://www.cosm.com/feeds/1.xml</feed> <status>frozen</status> <description>This is a room somewhere</description> <icon>http://www.roomsomewhere/icon.png</icon> <website>http://www.roomsomewhere/</website> <email>myemail@roomsomewhere</email> <data id="1"> <datapoints xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.eeml.org/xsd/0.5.1"> <value>0</value> <value>1</value> <value at="2007-05-04T18:13:51+00:00">2</value> </datapoints> </data> </environment> </eeml> """), result, reporter=self.fail))
def __init__(self, url, key): """ :param url: the api url either '/v2/feeds/1275.xml' or 1275 :type url: `str` :param key: your personal api key :type key: `str` """ if str(url) == url: if(url_pattern.match(url)): self._url = url else: raise ValueError("The url argument has to be in the form '/v2/feeds/1275.xml' or 1275") else: try: if int(url) == url: self._url = '/v2/feeds/' + str(url) + '.xml' else: raise TypeError('') except TypeError: raise TypeError("The url argument has to be in the form '/v2/feeds/1275.xml' or 1275") self._key = key self._eeml = eeml.create_eeml(eeml.Environment(), None, [])
def test_good_datapoints(self): env = Environment('A Room Somewhere', 'http://www.cosm.com/feeds/1.xml', 'frozen', 'This is a room somewhere', 'http://www.roomsomewhere/icon.png', 'http://www.roomsomewhere/', 'myemail@roomsomewhere', updated=datetime(2007, 5, 4, 18, 13, 51, 0, pytz.utc), creator='http://www.somewhere', id_=1) datapoints = DataPoints(1, [(0,), (1,), (2, datetime(2007, 5, 4, 18, 13, 51, 0, pytz.utc))]) result = create_eeml(env, None, datapoints).toeeml() assert_true(xml_compare(etree.fromstring( """ <eeml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.eeml.org/xsd/0.5.1" xsi:schemaLocation="http://www.eeml.org/xsd/0.5.1 http://www.eeml.org/xsd/0.5.1/0.5.1.xsd" version="0.5.1"> <environment updated="2007-05-04T18:13:51+00:00" creator="http://www.somewhere" id="1"> <title>A Room Somewhere</title> <feed>http://www.cosm.com/feeds/1.xml</feed> <status>frozen</status> <description>This is a room somewhere</description> <icon>http://www.roomsomewhere/icon.png</icon> <website>http://www.roomsomewhere/</website> <email>myemail@roomsomewhere</email> <data id="1"> <datapoints xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.eeml.org/xsd/0.5.1"> <value>0</value> <value>1</value> <value at="2007-05-04T18:13:51+00:00">2</value> </datapoints> </data> </environment> </eeml> """), result, reporter=self.fail))
def test_good_create_doc(self): env = Environment('A Room Somewhere', 'http://www.cosm.com/feeds/1.xml', 'frozen', 'This is a room somewhere', 'http://www.roomsomewhere/icon.png', 'http://www.roomsomewhere/', 'myemail@roomsomewhere', updated='2007-05-04T18:13:51.0Z', creator='http://www.somewhere', id_=1) loc = Location('physical', 'My Room', 32.4, 22.7, 0.2, 'indoor', 'fixed') u = Unit('Celsius', 'derivedSI', 'C') dat = [] dat.append( Data(0, 36.2, minValue=23.8, maxValue=48.0, unit=u, tags=['temperature'])) u = Unit('blushesPerHour', 'contextDependentUnits') dat.append( Data(1, 84.2, minValue=0, maxValue=100, unit=u, tags=['blush', 'redness', 'embarrasement'])) u = Unit('meter', 'basicSI', 'm') dat.append( Data(2, 12.3, minValue=0, unit=u, tags=['length', 'distance', 'extension'])) intermed = etree.tostring(create_eeml( env, loc, dat).toeeml()) # Broken down to help with error-checking final = etree.fromstring(intermed) assert_true( xml_compare(etree.fromstring(""" <eeml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.eeml.org/xsd/0.5.1" xsi:schemaLocation="http://www.eeml.org/xsd/0.5.1 http://www.eeml.org/xsd/0.5.1/0.5.1.xsd" version="0.5.1"> <environment creator="http://www.somewhere" id="1" updated="2007-05-04T18:13:51.0Z"> <title>A Room Somewhere</title> <feed>http://www.cosm.com/feeds/1.xml</feed> <status>frozen</status> <description>This is a room somewhere</description> <icon>http://www.roomsomewhere/icon.png</icon> <website>http://www.roomsomewhere/</website> <email>myemail@roomsomewhere</email> <location disposition="fixed" domain="physical" exposure="indoor"> <name>My Room</name> <lat>32.4</lat> <lon>22.7</lon> <ele>0.2</ele> </location> <data id="0"> <tag>temperature</tag> <current_value maxValue="48.0" minValue="23.8">36.2</current_value> <unit symbol="C" type="derivedSI">Celsius</unit> </data> <data id="1"> <tag>blush</tag> <tag>redness</tag> <tag>embarrasement</tag> <current_value maxValue="100" minValue="0">84.2</current_value> <unit type="contextDependentUnits">blushesPerHour</unit> </data> <data id="2"> <tag>length</tag> <tag>distance</tag> <tag>extension</tag> <current_value minValue="0">12.3</current_value> <unit symbol="m" type="basicSI">meter</unit> </data> </environment> </eeml> """), final, reporter=self.fail))
def test_good_create_doc(self): env = Environment('A Room Somewhere', 'http://www.cosm.com/feeds/1.xml', 'frozen', 'This is a room somewhere', 'http://www.roomsomewhere/icon.png', 'http://www.roomsomewhere/', 'myemail@roomsomewhere', updated='2007-05-04T18:13:51.0Z', creator='http://www.somewhere', id_=1) loc = Location('physical', 'My Room', 32.4, 22.7, 0.2, 'indoor', 'fixed') u = Unit('Celsius', 'derivedSI', 'C') dat = [] dat.append(Data(0, 36.2, minValue=23.8, maxValue=48.0, unit = u, tags=['temperature'])) u = Unit('blushesPerHour', 'contextDependentUnits') dat.append(Data(1, 84.2, minValue=0, maxValue=100, unit = u, tags=['blush', 'redness', 'embarrasement'])) u = Unit('meter', 'basicSI', 'm') dat.append(Data(2, 12.3, minValue=0, unit = u, tags=['length', 'distance', 'extension'])) intermed = etree.tostring( create_eeml(env, loc, dat).toeeml()) # Broken down to help with error-checking final = etree.fromstring(intermed) assert_true(xml_compare(etree.fromstring( """ <eeml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.eeml.org/xsd/0.5.1" xsi:schemaLocation="http://www.eeml.org/xsd/0.5.1 http://www.eeml.org/xsd/0.5.1/0.5.1.xsd" version="0.5.1"> <environment creator="http://www.somewhere" id="1" updated="2007-05-04T18:13:51.0Z"> <title>A Room Somewhere</title> <feed>http://www.cosm.com/feeds/1.xml</feed> <status>frozen</status> <description>This is a room somewhere</description> <icon>http://www.roomsomewhere/icon.png</icon> <website>http://www.roomsomewhere/</website> <email>myemail@roomsomewhere</email> <location disposition="fixed" domain="physical" exposure="indoor"> <name>My Room</name> <lat>32.4</lat> <lon>22.7</lon> <ele>0.2</ele> </location> <data id="0"> <tag>temperature</tag> <current_value maxValue="48.0" minValue="23.8">36.2</current_value> <unit symbol="C" type="derivedSI">Celsius</unit> </data> <data id="1"> <tag>blush</tag> <tag>redness</tag> <tag>embarrasement</tag> <current_value maxValue="100" minValue="0">84.2</current_value> <unit type="contextDependentUnits">blushesPerHour</unit> </data> <data id="2"> <tag>length</tag> <tag>distance</tag> <tag>extension</tag> <current_value minValue="0">12.3</current_value> <unit symbol="m" type="basicSI">meter</unit> </data> </environment> </eeml> """), final, reporter=self.fail))