Fetching contributors…
Cannot retrieve contributors at this time
83 lines (68 sloc) 3.62 KB
from RMParserFramework.rmParser import RMParser # Mandatory include for parser definition
from RMUtilsFramework.rmLogging import log # Optional include for logging
from RMUtilsFramework.rmTimeUtils import *
from xml.etree import ElementTree as e # Your parser needed libraries
class AustraliaBOM(RMParser):
parserName = "Australia BoM" # Your parser name
parserDescription = " Commonwealth of Australia Bureau of Meteorology" # A description for this parser
parserEnabled = True
parserInterval = 3600 # Your parser running interval in seconds
parserDebug = True # Don't show extra debug messages
params = {"city": "Toowoomba" } # Internal params that can be changed with API call /parser/{id}/params
def isEnabledForLocation(self, timezone, lat, long):
return AustraliaBOM.parserEnabled
# The function that will be executed must have this name
def perform(self):
# downloading data from a URL convenience function since other python libraries can be used
URL = ""
data = self.openURL(URL)
if data is None:
self.lastKnownError = "Error: No data received from server"
#xmldata = e.parse("/tmp/IDQ11295.xml")
xmldata = e.parse(data)
for node in xmldata.getroot().getiterator(tag = "area"):
if node.attrib['description'] != self.params["city"]:
for subnode in node.getiterator(tag = "forecast-period"):
subnodeDate = subnode.get("start-time-utc")
subnodeTimestamp = rmTimestampFromDateAsString(subnodeDate, '%Y-%m-%dT%H:%M:%SZ')"%s" % subnodeDate)
for element in subnode.getiterator(tag = "element"):
mint = None
maxt = None
qpfMin = None
qpfMax = None
qpfAvg = None
type = element.get("type")
if type == "air_temperature_minimum":
mint = self.__toFloat(element.text)"\tMin Temp: %s" % mint)
self.addValue(RMParser.dataType.MINTEMP, subnodeTimestamp, mint)
log.debug("Cannot get minimum temperature")
elif type == "air_temperature_maximum":
maxt = self.__toFloat(element.text)
self.addValue(RMParser.dataType.MAXTEMP, subnodeTimestamp, maxt)"\tMax Temp: %s" % maxt)
log.debug("Cannot get max temperature")
elif type == "precipitation_range":
qpfMin, _, qpfMax, _ = element.text.split() # will result in ['15', 'to', '35', 'mm']
qpfAvg = (self.__toFloat(qpfMin) + self.__toFloat(qpfMax))/2"\tQPF Avg: %s" % qpfAvg)
self.addValue(RMParser.dataType.QPF, subnodeTimestamp, qpfAvg)
log.debug("Cannot get precipitation forecast")
if self.parserDebug:
def __toFloat(self, value):
if value is None:
return value
return float(value)
if __name__ == '__main__':
p = AustraliaBOM()