|
| 1 | +# Python Standard Library Imports |
| 2 | +import datetime |
| 3 | + |
1 | 4 | # Third Party (PyPI) Imports |
2 | 5 | import requests |
3 | 6 | import rollbar |
@@ -208,20 +211,38 @@ def revoke_access(self): |
208 | 211 | # Activity |
209 | 212 | # https://dev.fitbit.com/build/reference/web-api/activity/ |
210 | 213 |
|
211 | | - def get_activity_steps_past_month(self): |
212 | | - """Get Steps for past month |
| 214 | + def get_activity_steps_for_period( |
| 215 | + self, end_date: datetime.date, period: str = '1y' |
| 216 | + ): |
| 217 | + """Get Steps for a given period |
213 | 218 |
|
214 | 219 | Requires the 'activity' permission' |
215 | | - https://dev.fitbit.com/docs/activity/ |
| 220 | +
|
| 221 | + References: |
| 222 | + - https://dev.fitbit.com/docs/activity/ |
| 223 | + - https://dev.fitbit.com/build/reference/web-api/activity-timeseries/get-activity-timeseries-by-date/ |
216 | 224 | """ |
217 | | - response = self.get('activity-steps-monthly') |
| 225 | + resource_args = (end_date.strftime('%Y-%m-%d'), period) |
| 226 | + response = self.get('activity-steps', resource_args=resource_args) |
218 | 227 | if response.status_code == 200: |
219 | 228 | activity = response.json()['activities-steps'] |
220 | 229 | activity = activity[::-1] |
221 | 230 | else: |
222 | 231 | activity = None |
223 | 232 | return activity |
224 | 233 |
|
| 234 | + def get_activity_steps_past_month(self): |
| 235 | + """Get Steps for past month""" |
| 236 | + today = self.user.profile.localized_date |
| 237 | + activity = self.get_activity_steps_for_period(today, '1m') |
| 238 | + return activity |
| 239 | + |
| 240 | + def get_activity_steps_past_year(self): |
| 241 | + """Get Steps for past year""" |
| 242 | + today = self.user.profile.localized_date |
| 243 | + activity = self.get_activity_steps_for_period(today, '1y') |
| 244 | + return activity |
| 245 | + |
225 | 246 | ## |
226 | 247 | # Body & Weight |
227 | 248 | # https://dev.fitbit.com/build/reference/web-api/body/ |
|
0 commit comments