def updateLocation(self): jdata = {"version": "1.1.0", "request_address": "true", "host": "maps.google.com", "address_language": "fi_FI"} wifi_towers = None cell_towers = None gps = sources.get_gps() if self.wifi is True: wifi_towers = sources.get_wifi() count_wifi_towers = 0 count_cell_towers = 0 if wifi_towers is not None: count_wifi_towers = len(wifi_towers) jdata["wifi_towers"] = wifi_towers if self.cell is True and self.modem is not None: mode = self.modem.get_operationmode() if mode is not None: jdata["radio_type"] = mode cell_towers = self.modem.get_cellid() if cell_towers is not None: count_cell_towers = len(cell_towers) jdata["cell_towers"] = cell_towers if gps is not None: jdata["location"] = { "latitude": gps["latitude"], "longitude": gps["longitude"], "accurancy": gps["accurancy"], } # update cell_towers to opencelli self.opencellid(jdata, update=True) if gps is None and wifi_towers is None and cell_towers is None: self.log.warning("Cannot get location, switch wlan or USB modem on") return self.log.debug("%s" % json.dumps(jdata)) loc = getPage("http://www.google.com/loc/json", jdata) if loc is not None: loc = json.loads(loc) loc = self.glocation(jdata) if not loc: loc = self.opencellid(jdata) if gps: retval = google.location2latitude(gps["latitude"], gps["longitude"], gps["accurancy"]) self.log.debug("latitude retval: %s" % retval) gps["count_wifi_towers"] = count_wifi_towers gps["count_cell_towers"] = count_cell_towers self.last = datetime.now() return gps elif loc is not None: retval = google.location2latitude(loc["latitude"], loc["longitude"], loc["accurancy"]) self.log.debug("latitude retval: %s" % retval) loc["count_wifi_towers"] = count_wifi_towers loc["count_cell_towers"] = count_cell_towers self.last = datetime.now() return loc else: self.log.warning("Cannot get current location") return
def loop(self): """Main loop""" if self.address is not None: self.location = self.getLocationByAddress(self.address) self.once = True if self.location is None: self.log.error("Can't find this address") return if self.cell is False and self.wifi is False and self.location is None: self.log.error("Need either cellurar or wifi access") sys.exit(1) if self.location is not None: retval = google.location2latitude(self.location[0], self.location[1], 10) self.log.debug("latitude retval: %s" % retval) return while True: self._update() if self.once: break sleep(self.delay)