check: add --check-login option, which checks that the APIs can be queried

This commit is contained in:
James Woglom
2021-03-22 22:38:07 -04:00
parent 89b40dcecb
commit 0b7e806a40
2 changed files with 58 additions and 0 deletions
+5
View File
@@ -8,6 +8,7 @@ import argparse
from tconnectsync.api import TConnectApi
from tconnectsync.process import process_time_range
from tconnectsync.autoupdate import process_auto_update
from tconnectsync.check import check_login
try:
from tconnectsync.secret import (
@@ -26,6 +27,7 @@ def parse_args():
parser.add_argument('--end-date', dest='end_date', type=str, default=None, help='The newest date to process data until (inclusive). Must be specified with --start-date.')
parser.add_argument('--days', dest='days', type=int, default=1, help='The number of days of t:connect data to read in. Cannot be used with --from-date and --until-date.')
parser.add_argument('--auto-update', dest='auto_update', action='store_const', const=True, default=False, help='If set, continuously checks for updates from t:connect and syncs with Nightscout.')
parser.add_argument('--check-login', dest='check_login', action='store_const', const=True, default=False, help='If set, checks that the provided t:connect credentials can be used to log in.')
return parser.parse_args()
@@ -47,6 +49,9 @@ def main():
tconnect = TConnectApi(TCONNECT_EMAIL, TCONNECT_PASSWORD)
if args.check_login:
return check_login(tconnect, time_start, time_end)
if args.auto_update:
print("Starting auto-update between", time_start, "and", time_end, "(PRETEND)" if args.pretend else "")
process_auto_update(tconnect, time_start, time_end, args.pretend)
+53
View File
@@ -0,0 +1,53 @@
from .nightscout import api_status
from .secret import PUMP_SERIAL_NUMBER
"""
Attempts to authenticate with each t:connect API,
and returns the output of a sample API call from each.
Also attempts to connect to the Nightscout API.
"""
def check_login(tconnect, time_start, time_end):
errors = 0
print("Logging in to t:connect ControlIQ API...")
try:
summary = tconnect.controliq.dashboard_summary(time_start, time_end)
print("ControlIQ dashboard summary: %s" % summary)
except Exception as e:
print("Error occurred querying ControlIQ API: %s" % e)
errors += 1
print("\nLogging in to t:connect WS2 API...")
try:
summary = tconnect.ws2.basaliqtech(time_start, time_end)
print("WS2 basaliq status: %s" % summary)
except Exception as e:
print("Error occurred querying WS2 API: %s" % e)
errors += 1
print("\nLogging in to t:connect Android API...")
try:
summary = tconnect.android.user_profile()
print("Android user profile: %s" % summary)
event = tconnect.android.last_event_uploaded(PUMP_SERIAL_NUMBER)
print("\nAndroid last uploaded event: %s" % event)
except Exception as e:
print("Error occurred querying Android API: %s" % e)
errors += 1
print("\nLogging in to Nightscout...")
try:
status = api_status()
print("\nNightscout status: %s" % status)
except Exception as e:
print("Error occurred querying Nightscout API: %s" % e)
errors += 1
if errors == 0:
print("\nNo API errors returned!")
else:
print("\nAPI errors occurred. Please check the errors above.")