Skip to content

Instantly share code, notes, and snippets.

@KitWallace
KitWallace / baroReader.py
Created September 16, 2012 17:06
the revised baroReader now that the BMP085 chip is available
def baroReader(interval_secs,altitude) :
baro = BMP085()
while True :
slbaro = round(baro.readSeaLevelPressure(altitude) / 100 ,2)
yield(slbaro)
time.sleep(interval_secs)
@KitWallace
KitWallace / BMP085-add.py
Created September 16, 2012 16:48
an function to convert observed pressure at altitude to sea-level. Formula is given in the datasheet
def readSeaLevelPressure(self, altitude=0) :
"Calculates the sea level pressure from a pressure at an altitude in metres"
pressure = float(self.readPressure())
pressureSL = pressure / pow( ( 1.0 - float(altitude) / 44330) , 5.225)
if (self.debug) :
print("DBG: Sea Level Pressure = %d" % (pressureSL))
return pressureSL
@KitWallace
KitWallace / tweet.py
Created September 6, 2012 00:42
Vocalising Tweets
#!/usr/bin/env python3
import time, json, re, sys
from urllib.request import urlopen
from urllib.parse import quote_plus
from email.utils import parsedate_tz
# local modules
import speak
@KitWallace
KitWallace / jxml.xq
Created September 5, 2012 22:22
JSON to XML (limited to a rather restricted set of JSON)
(:
a hack conversion from some forms of json to xml
presumption is that [ ] { } only used as json syntax not as characters in quoted strings
parsing of comma-separated text supports embedded , and : , relying on "\s*: as a separator
if the hint <rough is present in the flags, arrays will be split on comma - this is needed because the
recursive algorithm for text parsing causes stack overflow after 99 iterations.
embedded HTML is not supported
root is div
un named arrays or blocks are enclosed in divs
element names are expected to be valid XML names
# start up the monitor and talker processes
python start_barometer.py &
python barometer_talk.py &
python simple_clock.py &
# the controller will take stdin character input from keyboard or presenter
# yacht1 is the current version of the menu
python controller.py yacht1
@KitWallace
KitWallace / forecast.py
Created August 31, 2012 13:08
Creating a simple forecast
"""
This forecast method comes from
http://www.sciencecompany.com/-W135.aspx
input is the current baro (in hPa) and the trend over 3 hours
"""
forecast1_table = \
(
(1022, ( (-0.1 , "Continued fair"),
@KitWallace
KitWallace / clock.xml
Created August 30, 2012 09:05
fragment of menu to control the talking clock
<item title="Clock" action="'Clock is '+ get('clock').status()">
<item action="'Clock is now '+ get('clock').toggle().put().status()"/>
</item>
@KitWallace
KitWallace / simple_clock.py
Created August 30, 2012 08:54
The talking clock can be switched on or off via a persistant switch object
#!/usr/bin/python
import time
import speak
from persistant import *
from switch import *
Switch("clock").put()
while True :
@KitWallace
KitWallace / switch.py
Created August 30, 2012 08:52
simple switch to control processes
from persistant import *
class Switch(Persistant) :
def __init__(self,name) :
self.name = name
self.on = True
def switch_on(self) :
self.on= True
@KitWallace
KitWallace / persistant.py
Created August 30, 2012 08:50
a superclass for simple persistance
import pickle
import time
def get(name) :
file = open("obj/"+name+".pkl","r")
return pickle.load(file)
class Persistant(object) :
def __init__(self,name) :