This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mark_ids(node) : | |
""" mark id attributes as IDs so that getElementById() works | |
""" | |
try: | |
node.setIdAttribute("id") | |
except: | |
pass | |
for child in node.childNodes : |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stations = {} | |
def station(name) : | |
try : | |
station = stations[name] | |
return station | |
except : | |
station_item = menu.item(name) | |
url = station_item.getAttribute("url") | |
refresh = station_item.getAttribute("refresh") | |
station = Weather(name,url,refresh) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in weather | |
substitutes = { | |
"W":"West","N":"North","S":"South","E":"East", | |
"km/h":"kilometers per hour","C":"Celsius","mph":"miles per hours", | |
"Mon":"Monday","Tue":"Tuesday","Wed":"Wednesday","Thu":"Thursday","Fri":"Friday","Sat":"Saturday","Sun":"Sunday", | |
"NNE":"Nor Nor East","NE":"Nor East","ENE":"East Nor East","ESE":"East Sow East", | |
"SE":"Sow East" ,"SSE" :"Sow Sow East", "SSW":"Sow Sow West","SW":"Sow West","WSW":"West Sow West", | |
"WNW":"West Nor West","NW":"Nor West","NNW":"Nor Nor West", | |
"%":"percent" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare function local:max_depth($node) { | |
if (exists($node)) | |
then max($node/*/(local:max_depth(.) + 1)) | |
else 0 | |
}; | |
let $n := <a> dsds<b>dsd<c/>sdd</b><b><c>sds<d/>dsd</c></b></a> | |
return local:max_depth($n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare function local:stick_to_seq($stick) { | |
if ($stick) | |
then (name($stick),local:stick_to_seq($stick/*)) | |
else () | |
}; | |
declare function local:seq_to_stick($seq) { | |
if (exists($seq)) | |
then element {$seq[1]} {local:seq_to_stick(subsequence($seq,2))} | |
else () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare function local:invert($stick) { | |
let $leaf := $stick//*[last()] | |
return local:invert1($leaf) | |
}; | |
declare function local:invert1($leaf) { | |
if (exists($leaf)) | |
then element {name($leaf)} { | |
local:invert1($leaf/..) | |
} | |
else () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
... | |
def __init__(self,id,url,rate) : | |
self.url = url | |
self.id = id | |
self.ts = 0 | |
self.rate = int(rate) | |
self.refresh() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def baroReader(interval_secs) : | |
""" dummy reader until the chip is added to the RPi | |
generator | |
""" | |
station = Weather("horfield","http://www.martynhicks.co.uk/weather/clientraw.txt") | |
while True : | |
station.refresh() | |
if station.baro is None : | |
time.sleep(10) | |
else : |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def baroSmoother(interval_secs,smooth_secs) : | |
baro = baroReader(interval_secs) | |
max = int(smooth_secs / interval_secs) | |
while True: | |
total_baro = 0 | |
for i in range(max) : | |
reading = baro.next() | |
total_baro += reading | |
average_baro = round(total_baro / max, 2) | |
yield(average_baro) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def monitor(self) : | |
reader = baroSmoother(self.interval_secs,self.smooth_secs) | |
for self.baro in reader : | |
self.history.add(self.baro) | |
self.updateTrend() | |
self.put() |