From 3c4150c542c6117292f29f2fa4906b0090d8e9b9 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 3 Jan 2024 20:18:29 -0800 Subject: [PATCH] timezoned: set only from gps (#30904) * timezoned: set only from gps * unused --- system/timezoned.py | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/system/timezoned.py b/system/timezoned.py index 4a881c53a3..2cfc0076e9 100755 --- a/system/timezoned.py +++ b/system/timezoned.py @@ -5,7 +5,6 @@ import time import subprocess from typing import NoReturn -import requests from timezonefinder import TimezoneFinder from openpilot.common.params import Params @@ -41,35 +40,18 @@ def main() -> NoReturn: # Get allowed timezones valid_timezones = subprocess.check_output('timedatectl list-timezones', shell=True, encoding='utf8').strip().split('\n') + timezone = params.get("Timezone", encoding='utf8') + if timezone is not None: + cloudlog.debug("Setting timezone based on param") + set_timezone(valid_timezones, timezone) + while True: time.sleep(60) - # Set based on param - timezone = params.get("Timezone", encoding='utf8') - if timezone is not None: - cloudlog.debug("Setting timezone based on param") - set_timezone(valid_timezones, timezone) - continue - location = params.get("LastGPSPosition", encoding='utf8') - # 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 - except requests.exceptions.RequestException: - cloudlog.exception("Error getting timezone based on IP") - continue - # Find timezone by reverse geocoding the last known gps location - else: + if location is not None: cloudlog.debug("Setting timezone based on GPS location") try: location = json.loads(location)