def post(self): stationid = self.request.get("stationid") threshold = self.request.get("threshold") twittername = self.request.get("twittername") logging.info("added alert on %s for %s to @%s", stationid, threshold, twittername) if stationid and threshold and twittername: t = TwitterAlert(stationid=stationid, amount=int(threshold), twittername=twittername) t.put() self.redirect("/station/%s/?flash=Alarm toegevoegd!" % stationid)
def get(self): logging.info("scanning twitter alerts") q = ParticulateData.all() q.filter("date", date.today()) results = q.fetch(1000) for result in results: # Check if there are outstanding alerts q2 = TwitterAlert.all() q2.filter("stationid", result.stationid) alerts = q2.fetch(1000) for alert in alerts: logging.info("result value %d alert on %d", result.value, alert.amount) if result.value > alert.amount: # Send Tweet targetuser = alert.twittername logging.info("tweet to %s", targetuser) updateString = ( "@%s De waarde voor station %s is morgen te hoog, nl: %d, zie: http://www.vervuilingsalarm.nl/station/%s/" % (targetuser, result.stationid, result.value, result.stationid) ) twitterQueue = taskqueue.Queue("twitterqueue") twitterTask = taskqueue.Task(url="/sendtweets/worker/", params={"update": updateString}) twitterQueue.add(twitterTask)