Skip to content

Commit

Permalink
updated log responses
Browse files Browse the repository at this point in the history
  • Loading branch information
laureng-hd committed May 14, 2024
1 parent 5e8d6f3 commit 59d3354
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 70 deletions.
8 changes: 3 additions & 5 deletions hdforce/GetAthletes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ def GetAthletes(inactive: bool = False) -> pd.DataFrame:
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -83,7 +80,7 @@ def GetAthletes(inactive: bool = False) -> pd.DataFrame:
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand All @@ -95,11 +92,12 @@ def GetAthletes(inactive: bool = False) -> pd.DataFrame:
headers = {"Authorization": f"Bearer {a_token}"}

# Create Response
response = requests.get(url, headers=headers)
if inactive:
logger.debug("GET Request: Athletes (inactive = true)")
else:
logger.debug("GET Request: Athletes (inactive = false)")
# GET Request
response = requests.get(url, headers=headers)

# Response Handling
# If Error show error
Expand Down
7 changes: 2 additions & 5 deletions hdforce/GetForceTime.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ def GetForceTime(testId: str) -> pd.DataFrame:
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -84,7 +81,7 @@ def GetForceTime(testId: str) -> pd.DataFrame:
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand All @@ -100,9 +97,9 @@ def GetForceTime(testId: str) -> pd.DataFrame:
url = f"{url_cloud}/forcetime/{tid}"

# GET Request
logger.debug(f"GET Force-Time data for test: {tid}")
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)
logger.debug(f"GET Force-Time data for test: {tid}")

# Check response status and handle data accordingly
if response.status_code != 200:
Expand Down
7 changes: 2 additions & 5 deletions hdforce/GetGroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ def GetGroups() -> pd.DataFrame:
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -70,7 +67,7 @@ def GetGroups() -> pd.DataFrame:
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand All @@ -82,8 +79,8 @@ def GetGroups() -> pd.DataFrame:
headers = {"Authorization": f"Bearer {a_token}"}

# Create Response
response = requests.get(url, headers=headers)
logger.debug("GET Request: Groups")
response = requests.get(url, headers=headers)

# Response Handling
# If Error show error
Expand Down
7 changes: 2 additions & 5 deletions hdforce/GetMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ def GetMetrics() -> pd.DataFrame:
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -75,7 +72,7 @@ def GetMetrics() -> pd.DataFrame:
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand All @@ -87,8 +84,8 @@ def GetMetrics() -> pd.DataFrame:
headers = {"Authorization": f"Bearer {a_token}"}

# Create Response
response = requests.get(url, headers=headers)
logger.debug("GET Request: Metrics.")
response = requests.get(url, headers=headers)

# Response Handling
# If Error show error
Expand Down
7 changes: 2 additions & 5 deletions hdforce/GetTags.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ def GetTags() -> pd.DataFrame:
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -72,7 +69,7 @@ def GetTags() -> pd.DataFrame:
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand All @@ -81,9 +78,9 @@ def GetTags() -> pd.DataFrame:
url = f"{url_cloud}/tags"

# GET Request
logger.debug("GET Request: Tags")
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)
logger.debug("GET Request: Tags")

# Response Handling
# If Error show error
Expand Down
7 changes: 2 additions & 5 deletions hdforce/GetTeams.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ def GetTeams() -> pd.DataFrame:
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -71,7 +68,7 @@ def GetTeams() -> pd.DataFrame:
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand All @@ -80,9 +77,9 @@ def GetTeams() -> pd.DataFrame:
url = f"{url_cloud}/teams"

# GET Request
logger.debug("GET Request: Teams.")
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)
logger.debug("GET Request: Teams.")

# Response Handling
# If Error show error
Expand Down
12 changes: 5 additions & 7 deletions hdforce/GetTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@ def GetTests(from_=None, to_=None, sync=False, active=True) -> pd.DataFrame:
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -87,7 +84,7 @@ def GetTests(from_=None, to_=None, sync=False, active=True) -> pd.DataFrame:
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand All @@ -111,16 +108,17 @@ def GetTests(from_=None, to_=None, sync=False, active=True) -> pd.DataFrame:
# Create URL for request
url = f"{url_cloud}{from_dt}{to_dt}"

# GET Request
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)

# Log request
if from_dt is not None and to_dt is not None:
logger.debug(f"Test Request from_dt to_dt")
elif from_dt is None:
logger.debug(f"Test Request to_dt")
elif to_dt is None:
logger.debug(f"Test Request from_dt")
# GET Request
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)

# Check response status and handle data accordingly
if response.status_code != 200:
Expand Down
11 changes: 4 additions & 7 deletions hdforce/GetTestsAth.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ def GetTestsAth(athleteId: str, from_: int = None, to_: int = None, sync: bool =
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -92,7 +89,7 @@ def GetTestsAth(athleteId: str, from_: int = None, to_: int = None, sync: bool =
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand Down Expand Up @@ -123,16 +120,16 @@ def GetTestsAth(athleteId: str, from_: int = None, to_: int = None, sync: bool =
# Create URL for request
url = f"{url_cloud}?athleteId={a_id}{from_dt}{to_dt}"

# GET Request
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)
# Log request
if from_dt is not None and to_dt is not None:
logger.debug(f"Athlete Test Request from_dt to_dt")
elif from_dt is None:
logger.debug(f"Athlete Test Request to_dt")
elif to_dt is None:
logger.debug(f"Athlete Test Request from_dt")
# GET Request
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)

# Check response status and handle data accordingly
if response.status_code != 200:
Expand Down
11 changes: 4 additions & 7 deletions hdforce/GetTestsGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ def GetTestsGroup(groupId: str, from_: int = None, to_: int = None, sync: bool =
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -91,7 +88,7 @@ def GetTestsGroup(groupId: str, from_: int = None, to_: int = None, sync: bool =
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand Down Expand Up @@ -122,16 +119,16 @@ def GetTestsGroup(groupId: str, from_: int = None, to_: int = None, sync: bool =
# Create URL for request
url = f"{url_cloud}?groupId={g_id}{from_dt}{to_dt}"

# GET Request
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)
# Log request
if from_dt is not None and to_dt is not None:
logger.debug(f"Group Test Request from_dt to_dt")
elif from_dt is None:
logger.debug(f"Group Test Request to_dt")
elif to_dt is None:
logger.debug(f"Group Test Request from_dt")
# GET Request
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)

# Check response status and handle data accordingly
if response.status_code != 200:
Expand Down
11 changes: 4 additions & 7 deletions hdforce/GetTestsTeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ def GetTestsTeam(teamId: str, from_: int = None, to_: int = None, sync: bool = F
# Retrieve Access Token and check expiration
a_token = ConfigManager.get_env_variable("ACCESS_TOKEN")
tokenExp = int(ConfigManager.get_env_variable("TOKEN_EXPIRATION"))
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# get current time in timestamp
now = datetime.datetime.now()
nowtime = datetime.datetime.timestamp(now)
if nowtime < tokenExp:
logger.debug(f"Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")

# Validate refresh token and expiration
if a_token is None:
Expand Down Expand Up @@ -91,7 +88,7 @@ def GetTestsTeam(teamId: str, from_: int = None, to_: int = None, sync: bool = F
logger.error("Failed to authenticate. Try AuthManager")
raise Exception("Failed to authenticate. Try AuthManage")
else:
logger.debug(f"New Access Token valid through: {datetime.datetime.fromtimestamp(tokenExp)}")
logger.debug(f"Access Token retrieved. expires {datetime.datetime.fromtimestamp(tokenExp)}")

# API Cloud URL
url_cloud = os.getenv("CLOUD_URL")
Expand All @@ -114,16 +111,16 @@ def GetTestsTeam(teamId: str, from_: int = None, to_: int = None, sync: bool = F
# Create URL for request
url = f"{url_cloud}?teamId={t_id}{from_dt}{to_dt}"

# GET Request
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)
# Log request
if from_dt is not None and to_dt is not None:
logger.debug(f"Team Test Request from_dt to_dt")
elif from_dt is None:
logger.debug(f"Team Test Request to_dt")
elif to_dt is None:
logger.debug(f"Team Test Request from_dt")
# GET Request
headers = {"Authorization": f"Bearer {a_token}"}
response = requests.get(url, headers=headers)

# Check response status and handle data accordingly
if response.status_code != 200:
Expand Down
Loading

0 comments on commit 59d3354

Please sign in to comment.