From cdf0cfc5b38a75ed411e48cb9e2b63ff951c9570 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Fri, 2 Jul 2021 15:45:28 +0200 Subject: [PATCH 1/4] fix cert error by using requests instead of urllib --- app_decoder.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app_decoder.py b/app_decoder.py index cb65296..fe5e24a 100755 --- a/app_decoder.py +++ b/app_decoder.py @@ -2,7 +2,6 @@ import json import os import traceback -from urllib import request from os import path from androguard.core.bytecodes.apk import APK @@ -41,11 +40,19 @@ def save_key_to_pem(pfx_data, pfx_password): encryption_algorithm=serialization.NoEncryption())) -def firstLaunchConfig(package_name, client_email, client_password, country_code, # pylint: disable=too-many-locals +def urlretrieve(url, path): + with open(path, 'wb') as f: + r = requests.get(url, stream=True) + r.raise_for_status() + for chunk in r.iter_content(1024): + f.write(chunk) + + +def firstLaunchConfig(package_name, client_email, client_password, country_code, # pylint: disable=too-many-locals config_prefix=""): - filename = package_name.split(".")[-1]+".apk" + filename = package_name.split(".")[-1] + ".apk" if not path.exists(filename): - request.urlretrieve(DOWNLOAD_URL+filename, filename) + urlretrieve(DOWNLOAD_URL + filename, filename) a = APK(filename) package_name = a.get_package() resources = a.get_android_resources() # .get_strings_resources() @@ -79,6 +86,7 @@ def firstLaunchConfig(package_name, client_email, client_password, country_code, msg += res.text except: pass + logger.error(msg) raise Exception(msg) try: res2 = requests.post( @@ -106,7 +114,6 @@ def firstLaunchConfig(package_name, client_email, client_password, country_code, pass logger.error(msg) Exception(msg) - # Psacc psacc = MyPSACC(None, client_id, client_secret, REMOTE_REFRESH_TOKEN, customer_id, BRAND[package_name]["realm"], country_code) From 046586e6eb0bc58bd417d9b10693b9e5934c892b Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Fri, 2 Jul 2021 15:46:14 +0200 Subject: [PATCH 2/4] add unbuffered option --- docker_files/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker_files/init.sh b/docker_files/init.sh index db326bc..b88b142 100755 --- a/docker_files/init.sh +++ b/docker_files/init.sh @@ -2,4 +2,4 @@ echo "Containerised psa_car_controller loading..." cd "$PSACC_CONFIG_DIR" ARGS="-p $PSACC_PORT -l 0.0.0.0 -b $PSACC_BASE_PATH $PSACC_OPTIONS" -python3 /psa_car_controller/server.py $ARGS +python3 -u /psa_car_controller/server.py $ARGS From fe43832d086ee5f116275059ad8431909e638855 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Fri, 2 Jul 2021 15:54:37 +0200 Subject: [PATCH 3/4] fix can't get altitude from null long and lat --- web/db.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/web/db.py b/web/db.py index 99759ed..8be44ba 100644 --- a/web/db.py +++ b/web/db.py @@ -18,6 +18,7 @@ NEW_BATTERY_COLUMNS = [["price", "INTEGER"], ["charging_mode", "TEXT"]] NEW_POSITION_COLUMNS = [["level_fuel", "INTEGER"], ["altitude", "INTEGER"]] NEW_BATTERY_CURVE_COLUMNS = [["rate", "INTEGER"], ["autonomy", "INTEGER"]] + def convert_sql_res(rows): return list(map(dict, rows)) @@ -47,11 +48,13 @@ class CustomSqliteConnection(sqlite3.Connection): self.commit() super().close() + class Database: callback_fct: Callable[[], None] = lambda: None DEFAULT_DB_FILE = 'info.db' db_initialized = False __thread_lock = Lock() + @staticmethod def convert_datetime_from_string(string): try: @@ -136,10 +139,10 @@ class Database: @staticmethod def clean_battery(conn): # delete charging longer than 17h - #conn.execute("DElETE FROM battery WHERE JULIANDAY(stop_at)-JULIANDAY(start_at)>0.7;") + # conn.execute("DElETE FROM battery WHERE JULIANDAY(stop_at)-JULIANDAY(start_at)>0.7;") # delete charging not finished longer than 17h - #conn.execute("DELETE from battery where stop_at is NULL and JULIANDAY()-JULIANDAY(start_at)>0.7;") - #delete little charge + # conn.execute("DELETE from battery where stop_at is NULL and JULIANDAY()-JULIANDAY(start_at)>0.7;") + # delete little charge conn.execute("DELETE FROM battery WHERE start_level >= end_level-1;") @staticmethod @@ -181,14 +184,15 @@ class Database: @staticmethod def add_altitude_to_db(conn): max_pos_by_req = 100 - nb_null = conn.execute( - "SELECT COUNT(1) FROM position WHERE altitude IS NULL;").fetchone()[0] + nb_null = conn.execute("SELECT COUNT(1) FROM position WHERE altitude IS NULL " + "and longitude IS NOT NULL AND latitude IS NOT NULL;").fetchone()[0] if nb_null > max_pos_by_req: logger.warning("There is %s to fetch from API, it can take some time", nb_null) try: while True: - res = conn.execute("SELECT DISTINCT latitude,longitude " - "FROM position WHERE altitude IS NULL LIMIT ?;", (max_pos_by_req,)).fetchall() + res = conn.execute("SELECT DISTINCT latitude,longitude FROM position WHERE altitude IS NULL " + "and longitude IS NOT NULL AND latitude IS NOT NULL LIMIT ?;", + (max_pos_by_req,)).fetchall() nb_res = len(res) if nb_res > 0: logger.debug("add altitude for %s positions point", nb_null) From 2cf0486d7e9d060baec8d8856231bf5693057e31 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Fri, 2 Jul 2021 16:05:28 +0200 Subject: [PATCH 4/4] fix citroen value --- web/config_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/config_views.py b/web/config_views.py index 7c2e3dd..d9ac622 100644 --- a/web/config_views.py +++ b/web/config_views.py @@ -23,7 +23,7 @@ config_layout = dbc.Row(dbc.Col(className="col-md-12 col-lg-2 ml-2", children=[ options=[ {"label": "Peugeot", "value": "com.psa.mym.mypeugeot"}, {"label": "Opel", "value": "com.psa.mym.myopel"}, - {"label": "Citroën", "value": "com.psa.mym.citroen"}, + {"label": "Citroën", "value": "com.psa.mym.mycitroen"}, {"label": "DS", "value": "com.psa.mym.myds"}, {"label": "Vauxhall", "value": "com.psa.mym.myvauxhall"} ],