Skip to content

Commit

Permalink
fixed nightscout timezone issue for SGS data; added linux support for…
Browse files Browse the repository at this point in the history
… login script (#70)
  • Loading branch information
sedy89 authored Feb 22, 2024
1 parent e37a546 commit aa0bf79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
11 changes: 2 additions & 9 deletions custom_components/carelink/nightscout_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,7 @@ def __get_treatments(self, input, key, value):

def __getDataStringFromIso(self, time, tz):
dt = datetime.fromisoformat(time.replace(".000-00:00", ""))
dt = dt.astimezone(tz)
timestamp = dt.timestamp()
date = int(timestamp * 1000)
date_string = dt.isoformat()
return date, date_string

def __getDataString(self, time, tz):
dt = datetime.strptime(time,"%Y-%m-%dT%H:%M:%S.%fZ")
dt = dt.replace(tzinfo=tz)
dt = dt.astimezone(tz)
timestamp = dt.timestamp()
date = int(timestamp * 1000)
Expand Down Expand Up @@ -376,7 +369,7 @@ def __getSGSEntries(self, sgs, tz):
trend, delta = self.__ns_trend(sgs[count], sgs[count-1])
except Exception:
pass
date, date_string=self.__getDataString(sg["datetime"], tz)
date, date_string=self.__getDataStringFromIso(sg["datetime"], tz)
result.append(dict(
device=NS_USER_AGENT,
direction=trend,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
colorlog==6.7.0
homeassistant==2023.8.0
homeassistant==2023.12.3
pip>=21.0,<23.2
ruff==0.0.292
18 changes: 17 additions & 1 deletion utils/carelink_carepartner_api_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@
import secrets
from time import sleep
import requests
import platform
import sys

import OpenSSL
from seleniumwire import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service


def setup_logging():
Expand Down Expand Up @@ -98,7 +102,19 @@ def reformat_csr(csr):
return csr

def do_captcha(url, redirect_url):
driver = webdriver.Firefox()
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = None
if platform.system() == 'Linux':
geckodriver_path = "/snap/bin/geckodriver" # path to your geckodriver
driver_service = Service(executable_path=geckodriver_path)
driver = webdriver.Firefox(options=options, service=driver_service)
elif platform.system() == 'Windows':
driver = webdriver.Firefox(options=options)
else:
print("OS not supported yet.")
sys.exit(1)
driver.get(url)

while True:
Expand Down

0 comments on commit aa0bf79

Please sign in to comment.