@@ -171,7 +171,6 @@ def user_profile_statistics() -> dict[str, Any]:
171171 # Gather summaries for the last 12 months
172172 user_profile = garth .UserProfile .get ()
173173 display_name = user_profile .display_name
174- # breakpoint()
175174
176175 # Get user statistics for last 12 months
177176 data = garth .connectapi (f"userstats-service/statistics/{ display_name } " )
@@ -214,21 +213,26 @@ def user_profile_statistics() -> dict[str, Any]:
214213 )
215214
216215 # Get detailed lifetime totals and convert to snake_case
217- lt = garth .connectapi (
218- f"usersummary-service/stats/connectLifetimeTotals/{ display_name } "
219- )
220- assert isinstance (lt , dict ), f"Expected dict, got { type (lt )} "
221- lifetime_totals = {
222- "total_distance" : lt ["totalDistance" ],
223- "total_distance_km" : round (lt ["totalDistance" ] / 1000 , 2 ),
224- "total_steps" : lt ["totalSteps" ],
225- "total_calories" : lt ["totalCalories" ],
226- "total_goals_met_in_days" : lt ["totalGoalsMetInDays" ],
227- "total_active_days" : lt ["totalActiveDays" ],
228- "total_wellness_distance" : lt ["totalWellnessDistance" ],
229- "total_wellness_distance_km" : round (lt ["totalWellnessDistance" ] / 1000 , 2 ),
230- "total_step_calories" : lt ["totalStepCalories" ],
231- }
216+ try :
217+ lt = garth .connectapi (
218+ f"usersummary-service/stats/connectLifetimeTotals/{ display_name } "
219+ )
220+ except Exception :
221+ # Investigate why for some users this endpoint raises 403 using the display_name
222+ lifetime_totals = {}
223+ else :
224+ assert isinstance (lt , dict ), f"Expected dict, got { type (lt )} "
225+ lifetime_totals = {
226+ "total_distance" : lt ["totalDistance" ],
227+ "total_distance_km" : round (lt ["totalDistance" ] / 1000 , 2 ),
228+ "total_steps" : lt ["totalSteps" ],
229+ "total_calories" : lt ["totalCalories" ],
230+ "total_goals_met_in_days" : lt ["totalGoalsMetInDays" ],
231+ "total_active_days" : lt ["totalActiveDays" ],
232+ "total_wellness_distance" : lt ["totalWellnessDistance" ],
233+ "total_wellness_distance_km" : round (lt ["totalWellnessDistance" ] / 1000 , 2 ),
234+ "total_step_calories" : lt ["totalStepCalories" ],
235+ }
232236
233237 # Organize final stats dictionary as requested
234238 stats = {
0 commit comments