Skip to content

Commit 85e1bac

Browse files
committed
Travis
1 parent b693eae commit 85e1bac

4 files changed

+89
-84
lines changed

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: python
2+
python:
3+
- "3.6"
4+
script:
5+
- pytest

ambientweather_livedata.py

+39-84
Original file line numberDiff line numberDiff line change
@@ -16,87 +16,42 @@ class SensorData(object):
1616
battery ('Normal')
1717
"""
1818

19-
20-
def parse(live_data_html):
21-
"""
22-
Extract sensor's data from html (LiveData.html from your ObserverIP)
23-
Returns touple with (sensor1, sensor2 -> SensorData)
24-
"""
25-
26-
tree = html.fromstring(live_data_html)
27-
title = tree.xpath('//title/text()')
28-
if title[0] != TITLE:
29-
raise Exception('Wrong html page. Good one have to have title {}'.format(TITLE))
30-
31-
inSensor = SensorData()
32-
time_str = tree.xpath('//input[@name="CurrTime"]/@value')[0]
33-
inSensor.time = datetime.strptime(time_str, '%H:%M %m/%d/%Y')
34-
inSensor.temp = float(tree.xpath('//input[@name="inTemp"]/@value')[0])
35-
inSensor.humidity = float(tree.xpath('//input[@name="inHumi"]/@value')[0])
36-
inSensor.abs_press = float(tree.xpath('//input[@name="AbsPress"]/@value')[0])
37-
inSensor.rel_press = float(tree.xpath('//input[@name="RelPress"]/@value')[0])
38-
inSensor.battery = tree.xpath('//input[@name="inBattSta"]/@value')[0]
39-
40-
outSensor = SensorData()
41-
outSensor.time = inSensor.time
42-
outSensor.temp = float(tree.xpath('//input[@name="outTemp"]/@value')[0])
43-
outSensor.humidity = float(tree.xpath('//input[@name="outHumi"]/@value')[0])
44-
outSensor.abs_press = inSensor.abs_press
45-
outSensor.rel_press = inSensor.rel_press
46-
outSensor.battery = tree.xpath('//input[@name="outBattSta2"]/@value')[0]
47-
48-
return inSensor, outSensor
49-
50-
51-
def get(url):
52-
"""
53-
Load ObserverIP live data page from the URL and parse it
54-
55-
Returns touple with (sensor1, sensor2 -> SensorData)
56-
"""
57-
58-
page = requests.get(url).content
59-
return parse(page)
60-
61-
62-
def test():
63-
with open('LiveData.html', 'r') as f:
64-
page = f.read()
65-
66-
inSensor, outSensor = parse(page)
67-
68-
print('Time: {}\n'.format(inSensor.time))
69-
print('''Indoor\n{delimiter}\nTemperature: {temp}\nHumidity: {humidity}
70-
Absolute preassure: {abs_press}\nRelative preassure: {rel_press}\nBattery status: {battery}\n'''.format(
71-
delimiter='='*20,
72-
temp=inSensor.temp,
73-
humidity=inSensor.humidity,
74-
abs_press=inSensor.abs_press,
75-
rel_press=inSensor.rel_press,
76-
battery=inSensor.battery
77-
))
78-
print('''Outdoor\n{delimiter}\nTemperature: {temp}\nHumidity: {humidity}
79-
Battery status: {battery}\n'''.format(
80-
delimiter='='*20,
81-
temp=inSensor.temp,
82-
humidity=inSensor.humidity,
83-
battery=inSensor.battery
84-
))
85-
86-
assert inSensor.time == datetime.strptime('2017/10/06 13:55:00', '%Y/%m/%d %H:%M:%S')
87-
assert inSensor.temp == 21.9
88-
assert inSensor.humidity == 50.0
89-
assert inSensor.abs_press == 744.29
90-
assert inSensor.rel_press == 728.31
91-
assert inSensor.battery == 'Normal'
92-
assert outSensor.temp == 10.1
93-
assert outSensor.humidity == 71.0
94-
assert outSensor.battery == 'Normal'
95-
96-
97-
if __name__ == '__main__':
98-
test()
99-
100-
101-
102-
19+
def parse(self, live_data_html):
20+
"""
21+
Extract sensor's data from html (LiveData.html from your ObserverIP)
22+
Returns touple with (sensor1, sensor2 -> SensorData)
23+
"""
24+
25+
tree = html.fromstring(live_data_html)
26+
title = tree.xpath('//title/text()')
27+
if title[0] != TITLE:
28+
raise Exception('Wrong html page. Good one have to have title {}'.format(TITLE))
29+
30+
inSensor = SensorData()
31+
time_str = tree.xpath('//input[@name="CurrTime"]/@value')[0]
32+
inSensor.time = datetime.strptime(time_str, '%H:%M %m/%d/%Y')
33+
inSensor.temp = float(tree.xpath('//input[@name="inTemp"]/@value')[0])
34+
inSensor.humidity = float(tree.xpath('//input[@name="inHumi"]/@value')[0])
35+
inSensor.abs_press = float(tree.xpath('//input[@name="AbsPress"]/@value')[0])
36+
inSensor.rel_press = float(tree.xpath('//input[@name="RelPress"]/@value')[0])
37+
inSensor.battery = tree.xpath('//input[@name="inBattSta"]/@value')[0]
38+
39+
outSensor = SensorData()
40+
outSensor.time = inSensor.time
41+
outSensor.temp = float(tree.xpath('//input[@name="outTemp"]/@value')[0])
42+
outSensor.humidity = float(tree.xpath('//input[@name="outHumi"]/@value')[0])
43+
outSensor.abs_press = inSensor.abs_press
44+
outSensor.rel_press = inSensor.rel_press
45+
outSensor.battery = tree.xpath('//input[@name="outBattSta2"]/@value')[0]
46+
47+
return inSensor, outSensor
48+
49+
def get(self, url):
50+
"""
51+
Load ObserverIP live data page from the URL and parse it
52+
53+
Returns touple with (sensor1, sensor2 -> SensorData)
54+
"""
55+
56+
page = requests.get(url).content
57+
return self.parse(page)

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lxml
2+
requests
3+

test/ambientweather_livedata_test.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from ambientweather_livedata import SensorData
2+
from _datetime import datetime
3+
4+
5+
def test():
6+
with open('LiveData.html', 'r') as f:
7+
page = f.read()
8+
9+
sensor_data = SensorData()
10+
inSensor, outSensor = sensor_data.parse(page)
11+
12+
print('Time: {}\n'.format(inSensor.time))
13+
print('''Indoor\n{delimiter}\nTemperature: {temp}\nHumidity: {humidity}
14+
Absolute preassure: {abs_press}\nRelative preassure: {rel_press}\nBattery status: {battery}\n'''.format(
15+
delimiter='='*20,
16+
temp=inSensor.temp,
17+
humidity=inSensor.humidity,
18+
abs_press=inSensor.abs_press,
19+
rel_press=inSensor.rel_press,
20+
battery=inSensor.battery
21+
))
22+
print('''Outdoor\n{delimiter}\nTemperature: {temp}\nHumidity: {humidity}
23+
Battery status: {battery}\n'''.format(
24+
delimiter='='*20,
25+
temp=inSensor.temp,
26+
humidity=inSensor.humidity,
27+
battery=inSensor.battery
28+
))
29+
30+
assert inSensor.time == datetime.strptime('2017/10/06 13:55:00', '%Y/%m/%d %H:%M:%S')
31+
assert inSensor.temp == 21.9
32+
assert inSensor.humidity == 50.0
33+
assert inSensor.abs_press == 744.29
34+
assert inSensor.rel_press == 728.31
35+
assert inSensor.battery == 'Normal'
36+
assert outSensor.temp == 10.1
37+
assert outSensor.humidity == 71.0
38+
assert outSensor.battery == 'Normal'
39+
40+
41+
42+

0 commit comments

Comments
 (0)