try to fix script check

This commit is contained in:
GJ Koolen 2025-10-20 12:00:23 +02:00
parent fa75a6b218
commit d18f70961d
2 changed files with 19 additions and 14 deletions

View file

@ -1,12 +1,14 @@
import requests import requests
import time import time
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import hashlib
import binascii
from datetime import datetime from datetime import datetime
from collections import deque from collections import deque
##### Mqtt vars ##### ##### Mqtt vars #####
broker_address = "192.168.1.160" broker_address = "192.168.1.160"
broker_port = 1883 broker_port = 1883
recieve_topic = "telegrambot/in/glucose/gj" recieve_topic = "telegrambot/in/glucose/gj"
send_topic = "telegrambot/out/gj" send_topic = "telegrambot/out/gj"
brokercreds = ["hass","Bruk#5"] brokercreds = ["hass","Bruk#5"]
@ -14,18 +16,21 @@ brokercreds = ["hass","Bruk#5"]
##### Variables ##### ##### Variables #####
# API JWT token, Account-Id and Patient_Id # API JWT token, Account-Id and Patient_Id
jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImM1ZGVhZGZiLTNlZDYtMTFlYS1hZjZmLTAyNDJhYzExMDAwYSIsImZpcnN0TmFtZSI6IkdlcnRqYW4iLCJsYXN0TmFtZSI6Iktvb2xlbiIsImNvdW50cnkiOiJOTCIsInJlZ2lvbiI6ImV1Iiwicm9sZSI6InBhdGllbnQiLCJlbWFpbCI6Imdqa29vbGVuQGdtYWlsLmNvbSIsInMiOiJsbHUuYW5kcm9pZCIsInNpZCI6IjkzYTZmMmU2LWRjNDQtNDA0Mi04YjBiLTcxMGQ3MzAyMzMyNSIsInRhc2tUeXBlIjoidG91IiwiZXhwIjoxNzYwMTkzMDM2LCJpYXQiOjE3NjAxODk0MzYsImp0aSI6ImU0NTRlYzljLTE2ZTMtNDQwMy05YjYyLTc0NjAxZTkzNDFjOSJ9.hiyrVjE2kWvBr2DjtPojdTDtkqNrPI57HubXYl4Kko0" jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImM1ZGVhZGZiLTNlZDYtMTFlYS1hZjZmLTAyNDJhYzExMDAwYSIsImZpcnN0TmFtZSI6IkdlcnRqYW4iLCJsYXN0TmFtZSI6Iktvb2xlbiIsImNvdW50cnkiOiJOTCIsInJlZ2lvbiI6ImV1Iiwicm9sZSI6InBhdGllbnQiLCJzIjoibGx1LmFuZHJvaWQiLCJzaWQiOiIyZDM3NTJmNy01M2EwLTQ2N2ItOTAyNS02YmIzODBmZTYxZWEiLCJleHAiOjE3NzY1MDYwNTIsImlhdCI6MTc2MDk1NDA1MiwianRpIjoiNDYzYmRiZjQtNjJiNi00N2I4LWJiNzYtN2FmMmJjNGY2YjkzIn0.0pxP3zagyWaTF-r0F9mHOtSsbsMwz3lUvzEnQQmDNek"
Account_ID = "dad20d62aeef891d94bda411af269900180cb7b84a0ce51d60b52463339935b1" #Account_ID = "dad20d62aeef891d94bda411af269900180cb7b84a0ce51d60b52463339935b1"
Patient_ID = "c5deadfb-3ed6-11ea-af6f-0242ac11000a" Patient_ID = "c5deadfb-3ed6-11ea-af6f-0242ac11000a"
# API endpoint for login # API endpoint for login
#url = f"https://api-eu.libreview.io/llu/connections/{Patient_ID}/graph" #url = f"https://api-eu.libreview.io/llu/connections/{Patient_ID}/graph"
url = f"https://libreview-proxy.onrender.com/eu/auth/continue/tou" url = f"https://libreview-proxy.onrender.com/eu/auth/continue/tou"
digest = hashlib.sha256(Patient_ID.encode('utf-8')).digest()
Account_ID = binascii.hexlify(digest).decode('utf-8')
# Headers # Headers
headers = { headers = {
"content-type": "application/json", # This nececcery "Accept": "application/json", # This nececcery
"product": "llu.android", # This nececcery "product": "llu.android", # This nececcery
"version": "4.13.0", # Version older then 4.12.0 gives error. "version": "4.16", # Version older then 4.12.0 gives error.
"Authorization": f"Bearer {jwt_token}", # JWT_token for login "Authorization": f"Bearer {jwt_token}", # JWT_token for login
"Account-Id" : Account_ID # Extra login credentials "Account-Id" : Account_ID # Extra login credentials
} }
@ -50,7 +55,7 @@ limits_max_hours = 4 # nr of hours in the above lists
last_bolus_time = time.time()-3600 last_bolus_time = time.time()-3600
last_bolus_type = 0 last_bolus_type = 0
GLUC_READOUT_PERIOD = 5 # in minutes GLUC_READOUT_PERIOD = 1 #5 # in minutes
GLUC_SLOPE_PERIOD = 30 # in minutes GLUC_SLOPE_PERIOD = 30 # in minutes
GLUC_BUFFER_LENGTH = round(GLUC_SLOPE_PERIOD/GLUC_READOUT_PERIOD) GLUC_BUFFER_LENGTH = round(GLUC_SLOPE_PERIOD/GLUC_READOUT_PERIOD)
gluc_buffer = deque([6.0] * GLUC_BUFFER_LENGTH, maxlen=GLUC_BUFFER_LENGTH) # The gluc_buffer always contains only the last xx elements. Initialized on 6.0 gluc_buffer = deque([6.0] * GLUC_BUFFER_LENGTH, maxlen=GLUC_BUFFER_LENGTH) # The gluc_buffer always contains only the last xx elements. Initialized on 6.0
@ -80,7 +85,7 @@ def main(url_main, headers_main):
response = requests.get(url_main, headers=headers_main) # json=payload response = requests.get(url_main, headers=headers_main) # json=payload
if response.status_code == 200: # If request has succeeded if response.status_code == 200: # If request has succeeded
data = response.json() data = response.json()
gluc_value = glucose_value(data) gluc_value = glucose_value(data)
print(f"current level: {gluc_value}") print(f"current level: {gluc_value}")
@ -105,7 +110,6 @@ def main(url_main, headers_main):
(gluc_slope > limits_table[last_bolus_type][int(hours_since_last_bolus)][1])): (gluc_slope > limits_table[last_bolus_type][int(hours_since_last_bolus)][1])):
print("Hey joh check je glucosepeil !") print("Hey joh check je glucosepeil !")
Mqtt.publish(send_topic, f"Hey joh check peil ! (lastbolus -{round(hours_since_last_bolus, 1)})") Mqtt.publish(send_topic, f"Hey joh check peil ! (lastbolus -{round(hours_since_last_bolus, 1)})")
else: # Request has failed else: # Request has failed
print(f"❌ Error: Could not connect to server: {response.status_code}") print(f"❌ Error: Could not connect to server: {response.status_code}")

View file

@ -1,7 +1,8 @@
import requests import requests
# API endpoint for login # API endpoint for login
url = "https://api-eu.libreview.io/llu/auth/login" # Replace with the actual API URL #url = "https://api-eu.libreview.io/llu/auth/login" # Replace with the actual API URL
url = "https://libreview-proxy.onrender.com/eu/llu/auth/login" # Replace with the actual API URL
# Login credentials # Login credentials
payload = { payload = {
@ -14,9 +15,9 @@ headers = {
'accept-encoding': 'gzip', 'accept-encoding': 'gzip',
'cache-control': 'no-cache', 'cache-control': 'no-cache',
'connection': 'Keep-Alive', 'connection': 'Keep-Alive',
'content-type': 'application/json', 'Accept': 'application/json',
'product': 'llu.android', 'product': 'llu.android',
'version': '4.7' 'version': '4.16'
} }
# Send the POST request # Send the POST request
@ -24,7 +25,7 @@ response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
# Ensure the response contains the expected structure # Ensure the response contains the expected structure
if data.get("status") == 0 and "authTicket" in data.get("data", {}): if data.get("status") == 0 and "authTicket" in data.get("data", {}):
jwt_token = data["data"]["authTicket"]["token"] jwt_token = data["data"]["authTicket"]["token"]
@ -33,4 +34,4 @@ if response.status_code == 200:
print("Status = ", data.get("status")) print("Status = ", data.get("status"))
print("Login failed: Unexpected response format") print("Login failed: Unexpected response format")
else: else:
print("Login failed:", response.status_code, response.text) print("Login failed:", response.status_code, response.text)