def run(self): """Trigger thread run and send message (given during construction) to all subscribed users """ the_print("thread starts. sender ready.") subscriptions = Subscription.query.all() for s in subscriptions: if s.handphone_verified == 1: the_print("prepare sms to " + s.handphone) if self.gps is None: self.send_message(s.handphone, self.msg) continue distance = latlng.distance(self.gps['lat'], self.gps['lng'], s.latitude, s.longtitude) the_print("distance: " + str(distance) + "km") if distance <= 10: the_print("within distance, sent sms to " + s.handphone) self.send_message(s.handphone, self.msg) else: the_print("too far, do not sent to" + s.handphone) the_print("all SMS sent. thread finished.")
def run(self): """Trigger thread run and send message (given during construction) to all subscribed users """ the_print("thread starts. email sender ready.") subscriptions = Subscription.query.all() for s in subscriptions: if s.email_verified == 1: the_print("prepare email to " + s.email) if self.gps is None: self.send_email_to(s.email, "SG Incident Alert", self.message) continue distance = latlng.distance(self.gps['lat'], self.gps['lng'], s.latitude, s.longtitude) the_print("distance: " + str(distance) + "km") if distance <= 10: self.send_email_to(s.email, "SG Incident Alert", self.message) the_print("email has been sent to " + s.email) else: the_print("distance too far, not send to" + s.email) the_print("finished sending email.")
def distance_to(self, other_device): """Returns the distance in meters to another device""" return distance(self.lat, self.lng, other_device.lat, other_device.lng)
def is_in_hospital(self): return distance(self.lat, self.lng, HOSPITAL_LAT, HOSPITAL_LNG) < HOSPITAL_RADIUS