Merge pull request #174 from flobz/develop

v2.4.2
This commit is contained in:
Florian BEZANNIER
2021-07-02 16:40:09 +02:00
committed by GitHub
4 changed files with 25 additions and 14 deletions
+12 -5
View File
@@ -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)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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"}
],
+11 -7
View File
@@ -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)