def update_stream(): """The mother of all tasks to update the stream with the latest data.""" logging.basicConfig(level=logging.DEBUG, filename="kofkofmtl.log") log = logging.getLogger("Stream Updater") data = fetch_for() now = datetime.datetime.now() found = False for station in data.stations: for measurement in station.measurements: if measurement.hour == now.hour: pollutants = [ k for (k,v) in measurement.pollutants.items() if v > 51 ] if pollutants: found = True log.debug("The measurement at %r at hour %d has the following: %r" % ( station.guess_name(), measurement.hour, measurement.pollutants )) send_air_message(station.guess_name(), pollutants) if not found: log.debug("No records tweeted on %s" % now)
def post_update(): """Posts an update to the twitter feed.""" send_air_message("Maisonneuve", ["NO2", "O3"])