def get_stations(configfile, db, station_filter): cursor = db.cursor() ret = cursor.execute("SELECT * FROM stations ORDER BY id") if (not ret): raise Exception("Failed to fetch station list") infile = open(configfile, 'r') config = json.load(infile) infile.close() sources = get_sources(config) stations = {} for row in cursor: station_id = row['id'] if station_filter and station_id not in station_filter: continue handler = row['handler'] if (handler not in sources): print "warning: %s doesnt have a valid handler (%s)" % (row['id'], handler) continue source = sources[handler] fields = { 'id': row['id'], 'friendlyname': row['friendlyname'], 'pollrate': row['pollrate'], 'pos_lat': row['position_lat'], 'pos_lon': row['position_lon'], 'description': row['description'], 'caps': source.get_capabilities(row['id']) } stations[station_id] = Station(fields, sources[handler]) return stations
def __init__(self, fields, source): self.fields = fields self.source = source self.caps = source.get_capabilities(self.id) self.fields['caps'] = self.caps