From 8f210c9fd7332b0b21ff8401dc7d029c79e3bcd7 Mon Sep 17 00:00:00 2001 From: Linus Dietz <45101649+Dielee@users.noreply.github.com> Date: Fri, 15 Mar 2024 10:27:51 +0100 Subject: [PATCH] Add dynamic header building including latest app version --- requirements.txt | 5 +++-- src/util.py | 12 ++++++++++++ src/volvo.py | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index fc8e167..ab85721 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -requests~=2.29.0 +requests~=2.31.0 dynaconf~=3.1.12 paho-mqtt~=1.6.1 Babel~=2.12.1 -pytz~=2023.3 \ No newline at end of file +pytz~=2023.3 +google_play_scraper~=1.2.6 \ No newline at end of file diff --git a/src/util.py b/src/util.py index a03beaa..2a40f26 100644 --- a/src/util.py +++ b/src/util.py @@ -5,6 +5,7 @@ import sys import config import json +from google_play_scraper import app from logging import handlers from datetime import datetime from const import units @@ -29,6 +30,17 @@ def filter(self, record: logging.LogRecord) -> bool: record.msg = re.sub(pattern, "", record.msg) return True +def get_volvo_app_version(): + result = app( + 'se.volvo.vcc', + lang='en', + country='us' + ) + + if "version" in result: + return result["version"] + else: + return "5.37.0" def save_to_json(data): with open('.token', 'w', encoding='utf-8') as f: diff --git a/src/volvo.py b/src/volvo.py index 08ad5a4..67f8d90 100644 --- a/src/volvo.py +++ b/src/volvo.py @@ -46,7 +46,7 @@ def authorize(renew_tokenfile=False): auth_session = requests.session() auth_session.headers = { "authorization": "Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc=", - "User-Agent": "vca-android/5.37.0", + "User-Agent": "vca-android/" + util.get_volvo_app_version(), "Accept-Encoding": "gzip", "Content-Type": "application/json; charset=utf-8" }