timezoned: set only from gps (#30904)

* timezoned: set only from gps

* unused
pull/30906/head
Adeeb Shihadeh 1 year ago committed by GitHub
parent fe40905849
commit 3c4150c542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      system/timezoned.py

@ -5,7 +5,6 @@ import time
import subprocess import subprocess
from typing import NoReturn from typing import NoReturn
import requests
from timezonefinder import TimezoneFinder from timezonefinder import TimezoneFinder
from openpilot.common.params import Params from openpilot.common.params import Params
@ -41,35 +40,18 @@ def main() -> NoReturn:
# Get allowed timezones # Get allowed timezones
valid_timezones = subprocess.check_output('timedatectl list-timezones', shell=True, encoding='utf8').strip().split('\n') valid_timezones = subprocess.check_output('timedatectl list-timezones', shell=True, encoding='utf8').strip().split('\n')
while True:
time.sleep(60)
# Set based on param
timezone = params.get("Timezone", encoding='utf8') timezone = params.get("Timezone", encoding='utf8')
if timezone is not None: if timezone is not None:
cloudlog.debug("Setting timezone based on param") cloudlog.debug("Setting timezone based on param")
set_timezone(valid_timezones, timezone) set_timezone(valid_timezones, timezone)
continue
location = params.get("LastGPSPosition", encoding='utf8') while True:
time.sleep(60)
# Find timezone based on IP geolocation if no gps location is available
if location is None:
cloudlog.debug("Setting timezone based on IP lookup")
try:
r = requests.get("https://ipapi.co/timezone", headers=REQUEST_HEADERS, timeout=10)
if r.status_code == 200:
set_timezone(valid_timezones, r.text)
else:
cloudlog.error(f"Unexpected status code from api {r.status_code}")
time.sleep(3600) # Don't make too many API requests location = params.get("LastGPSPosition", encoding='utf8')
except requests.exceptions.RequestException:
cloudlog.exception("Error getting timezone based on IP")
continue
# Find timezone by reverse geocoding the last known gps location # Find timezone by reverse geocoding the last known gps location
else: if location is not None:
cloudlog.debug("Setting timezone based on GPS location") cloudlog.debug("Setting timezone based on GPS location")
try: try:
location = json.loads(location) location = json.loads(location)

Loading…
Cancel
Save