Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix for #141: Support for multiple garmin users #144

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions withings_sync/garmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
log = logging.getLogger("garmin")


HOME = os.getenv('HOME', '.')
GARMIN_SESSION = os.getenv('GARMIN_SESSION', HOME + '/.garmin_session')


class LoginSucceeded(Exception):
"""Used to raise on LoginSucceeded"""

Expand All @@ -27,8 +31,8 @@ def __init__(self) -> None:

def login(self, email=None, password=None):
logged_in = False
if os.path.exists('./garmin_session'):
self.client.load('./garmin_session')
if os.path.exists(GARMIN_SESSION):
self.client.load(GARMIN_SESSION)
try:
self.client.username
logged_in = True
Expand All @@ -38,7 +42,7 @@ def login(self, email=None, password=None):
if not logged_in:
try:
self.client.login(email, password)
self.client.dump('./garmin_session')
self.client.dump(GARMIN_SESSION)
except Exception as ex:
raise APIException("Authentication failure: {}. Did you enter correct credentials?".format(ex))

Expand Down
6 changes: 5 additions & 1 deletion withings_sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from datetime import date, datetime
from importlib.metadata import version

# Load the environment variables from a .env (dotenv) file.
# This is done prior to importing other modules such that all variables,
# also the ones accessed in those modules, can be set in the dotenv file.
dotenv.load_dotenv()

from withings_sync.withings2 import WithingsAccount
from withings_sync.garmin import GarminConnect
from withings_sync.trainerroad import TrainerRoad
Expand All @@ -30,7 +35,6 @@ def load_variable(env_var, secrets_file):
# value read from the secrets file.
return os.getenv(env_var, value)

dotenv.load_dotenv()

GARMIN_USERNAME = load_variable('GARMIN_USERNAME', "/run/secrets/garmin_username")
GARMIN_PASSWORD = load_variable('GARMIN_PASSWORD', "/run/secrets/garmin_password")
Expand Down