|
2 | 2 | # SPDX-License-Identifier: MIT |
3 | 3 | # Coded for Circuit Python 8.2.x |
4 | 4 | """Fitbit API Example""" |
5 | | -# pylint: disable=import-error, disable=no-member |
| 5 | +# pylint: disable=no-member |
6 | 6 |
|
7 | 7 | import os |
8 | 8 | import time |
@@ -174,17 +174,16 @@ def time_calc(input_time): |
174 | 174 | print(f"Current Refresh Token: {Refresh_Token}") |
175 | 175 | # TOKEN REFRESH POST |
176 | 176 | try: |
177 | | - fitbit_oauth_refresh_POST = requests.post( |
| 177 | + with requests.post( |
178 | 178 | url=FITBIT_OAUTH_TOKEN, |
179 | 179 | data=FITBIT_OAUTH_REFRESH_TOKEN, |
180 | 180 | headers=FITBIT_OAUTH_HEADER, |
181 | | - ) |
| 181 | + ) as fitbit_oauth_refresh_POST: |
| 182 | + fitbit_refresh_oauth_json = fitbit_oauth_refresh_POST.json() |
182 | 183 | except adafruit_requests.OutOfRetries as ex: |
183 | 184 | print(f"OutOfRetries: {ex}") |
184 | 185 | break |
185 | 186 | try: |
186 | | - fitbit_refresh_oauth_json = fitbit_oauth_refresh_POST.json() |
187 | | - |
188 | 187 | fitbit_new_token = fitbit_refresh_oauth_json["access_token"] |
189 | 188 | if DEBUG: |
190 | 189 | print("Your Private SHA-256 Token: ", fitbit_new_token) |
@@ -252,9 +251,9 @@ def time_calc(input_time): |
252 | 251 | print(" | Attempting to GET Fitbit JSON!") |
253 | 252 | FBIS = FITBIT_INTRADAY_SOURCE |
254 | 253 | FBH = fitbit_header |
255 | | - fitbit_get_response = requests.get(url=FBIS, headers=FBH) |
256 | 254 | try: |
257 | | - fitbit_json = fitbit_get_response.json() |
| 255 | + with requests.get(url=FBIS, headers=FBH) as fitbit_get_response: |
| 256 | + fitbit_json = fitbit_get_response.json() |
258 | 257 | except ConnectionError as e: |
259 | 258 | print("Connection Error:", e) |
260 | 259 | print("Retrying in 10 seconds") |
@@ -318,9 +317,9 @@ def time_calc(input_time): |
318 | 317 | print(" | Attempting to GET Device JSON!") |
319 | 318 | FBDS = FITBIT_DEVICE_SOURCE |
320 | 319 | FBH = fitbit_header |
321 | | - fitbit_get_device_response = requests.get(url=FBDS, headers=FBH) |
322 | 320 | try: |
323 | | - fitbit_device_json = fitbit_get_device_response.json() |
| 321 | + with requests.get(url=FBDS, headers=FBH) as fitbit_get_device_response: |
| 322 | + fitbit_device_json = fitbit_get_device_response.json() |
324 | 323 | except ConnectionError as e: |
325 | 324 | print("Connection Error:", e) |
326 | 325 | print("Retrying in 10 seconds") |
|
0 commit comments