otf-api 0.4.0__tar.gz → 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {otf_api-0.4.0 → otf_api-0.6.0}/PKG-INFO +3 -5
  2. {otf_api-0.4.0 → otf_api-0.6.0}/README.md +1 -1
  3. {otf_api-0.4.0 → otf_api-0.6.0}/pyproject.toml +2 -9
  4. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/__init__.py +1 -1
  5. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/api.py +20 -64
  6. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/auth.py +2 -1
  7. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/__init__.py +0 -2
  8. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/base.py +1 -62
  9. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/__init__.py +0 -2
  10. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/bookings.py +0 -78
  11. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/classes.py +0 -77
  12. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/performance_summary_list.py +2 -2
  13. otf_api-0.4.0/src/otf_api/cli/__init__.py +0 -4
  14. otf_api-0.4.0/src/otf_api/cli/_utilities.py +0 -60
  15. otf_api-0.4.0/src/otf_api/cli/app.py +0 -172
  16. otf_api-0.4.0/src/otf_api/cli/bookings.py +0 -231
  17. otf_api-0.4.0/src/otf_api/cli/prompts.py +0 -162
  18. otf_api-0.4.0/src/otf_api/models/responses/workouts.py +0 -78
  19. {otf_api-0.4.0 → otf_api-0.6.0}/AUTHORS.md +0 -0
  20. {otf_api-0.4.0 → otf_api-0.6.0}/LICENSE +0 -0
  21. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/body_composition_list.py +0 -0
  22. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/book_class.py +0 -0
  23. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/cancel_booking.py +0 -0
  24. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/challenge_tracker_content.py +0 -0
  25. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/challenge_tracker_detail.py +0 -0
  26. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/enums.py +0 -0
  27. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/favorite_studios.py +0 -0
  28. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/latest_agreement.py +0 -0
  29. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/lifetime_stats.py +0 -0
  30. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/member_detail.py +0 -0
  31. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/member_membership.py +0 -0
  32. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/member_purchases.py +0 -0
  33. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/out_of_studio_workout_history.py +0 -0
  34. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/performance_summary_detail.py +0 -0
  35. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/studio_detail.py +0 -0
  36. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/studio_services.py +0 -0
  37. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/telemetry.py +0 -0
  38. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/telemetry_hr_history.py +0 -0
  39. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/telemetry_max_hr.py +0 -0
  40. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/models/responses/total_classes.py +0 -0
  41. {otf_api-0.4.0 → otf_api-0.6.0}/src/otf_api/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: otf-api
3
- Version: 0.4.0
3
+ Version: 0.6.0
4
4
  Summary: Python OrangeTheory Fitness API Client
5
5
  License: MIT
6
6
  Author: Jessica Smith
@@ -18,7 +18,7 @@ Classifier: Topic :: Internet :: WWW/HTTP
18
18
  Classifier: Topic :: Software Development :: Libraries
19
19
  Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
20
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
- Requires-Dist: aiohttp (==3.9.5)
21
+ Requires-Dist: aiohttp (==3.8.*)
22
22
  Requires-Dist: humanize (>=4.9.0,<5.0.0)
23
23
  Requires-Dist: inflection (==0.5.*)
24
24
  Requires-Dist: loguru (==0.7.2)
@@ -27,15 +27,13 @@ Requires-Dist: pint (==0.24.*)
27
27
  Requires-Dist: pycognito (==2024.5.1)
28
28
  Requires-Dist: pydantic (==2.7.3)
29
29
  Requires-Dist: python-box (>=7.2.0,<8.0.0)
30
- Requires-Dist: readchar (>=4.1.0,<5.0.0)
31
- Requires-Dist: typer (>=0.12.3,<0.13.0)
32
30
  Project-URL: Documentation, https://otf-api.readthedocs.io/en/stable/
33
31
  Description-Content-Type: text/markdown
34
32
 
35
33
  Simple API client for interacting with the OrangeTheory Fitness APIs.
36
34
 
37
35
 
38
- This library allows access to the OrangeTheory API to retrieve workouts and performance data, class schedules, studio information, and bookings. It is a work in progress, currently only allowing access to GET calls, but my goal is to expand it to include POST, PUT, and DELETE calls as well.
36
+ This library allows access to the OrangeTheory API to retrieve workouts and performance data, class schedules, studio information, and bookings.
39
37
 
40
38
  ## Installation
41
39
  ```bash
@@ -1,7 +1,7 @@
1
1
  Simple API client for interacting with the OrangeTheory Fitness APIs.
2
2
 
3
3
 
4
- This library allows access to the OrangeTheory API to retrieve workouts and performance data, class schedules, studio information, and bookings. It is a work in progress, currently only allowing access to GET calls, but my goal is to expand it to include POST, PUT, and DELETE calls as well.
4
+ This library allows access to the OrangeTheory API to retrieve workouts and performance data, class schedules, studio information, and bookings.
5
5
 
6
6
  ## Installation
7
7
  ```bash
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "otf-api"
3
- version = "0.4.0"
3
+ version = "0.6.0"
4
4
  description = "Python OrangeTheory Fitness API Client"
5
5
  authors = ["Jessica Smith <j.smith.git1@gmail.com>"]
6
6
  license = "MIT"
@@ -22,7 +22,7 @@ classifiers = [
22
22
 
23
23
  [tool.poetry.dependencies]
24
24
  python = "^3.10"
25
- aiohttp = "3.9.5"
25
+ aiohttp = "3.8.*"
26
26
  humanize = "^4.9.0"
27
27
  inflection = "0.5.*"
28
28
  loguru = "0.7.2"
@@ -31,8 +31,6 @@ pint = "0.24.*"
31
31
  pycognito = "2024.5.1"
32
32
  pydantic = "2.7.3"
33
33
  python-box = "^7.2.0"
34
- readchar = "^4.1.0"
35
- typer = "^0.12.3"
36
34
 
37
35
  [tool.poetry.group.dev.dependencies]
38
36
  aioresponses = "0.7.6"
@@ -70,14 +68,9 @@ setuptools = "^70.0.0"
70
68
  virtualenv = "^20.26.2"
71
69
 
72
70
 
73
- [tool.poetry.group.cli.dependencies]
74
-
75
71
  [build-system]
76
72
  requires = ["poetry-core"]
77
73
  build-backend = "poetry.core.masonry.api"
78
74
 
79
75
  [tool.pytest.ini_options]
80
76
  pythonpath = ["src"]
81
-
82
- [tool.poetry.scripts]
83
- otf = "otf_api.cli:base_app"
@@ -6,7 +6,7 @@ from loguru import logger
6
6
  from .api import Otf
7
7
  from .auth import OtfUser
8
8
 
9
- __version__ = "0.4.0"
9
+ __version__ = "0.6.0"
10
10
 
11
11
 
12
12
  __all__ = ["Otf", "OtfUser"]
@@ -3,7 +3,6 @@ import contextlib
3
3
  import json
4
4
  import typing
5
5
  from datetime import date, datetime
6
- from math import ceil
7
6
  from typing import Any
8
7
 
9
8
  import aiohttp
@@ -43,7 +42,6 @@ from otf_api.models import (
43
42
  TelemetryHrHistory,
44
43
  TelemetryMaxHr,
45
44
  TotalClasses,
46
- WorkoutList,
47
45
  )
48
46
 
49
47
 
@@ -226,32 +224,15 @@ class Otf:
226
224
  """Perform an API request to the performance summary API."""
227
225
  return await self._do(method, API_IO_BASE_URL, url, params, headers)
228
226
 
229
- async def get_workouts(self) -> WorkoutList:
230
- """Get the list of workouts from OT Live.
227
+ async def get_body_composition_list(self) -> BodyCompositionList:
228
+ """Get the member's body composition list.
231
229
 
232
230
  Returns:
233
- WorkoutList: The list of workouts.
234
-
235
- Info:
236
- ---
237
- This returns data from the same api the [OT Live website](https://otlive.orangetheory.com/) uses.
238
- It is quite a bit of data, and all workouts going back to ~2019. The data includes the class history
239
- UUID, which can be used to get telemetry data for a specific workout.
231
+ Any: The member's body composition list.
240
232
  """
233
+ data = await self._default_request("GET", f"/member/members/{self._member_uuid}/body-composition")
241
234
 
242
- res = await self._default_request("GET", "/virtual-class/in-studio-workouts")
243
-
244
- return WorkoutList(workouts=res["data"])
245
-
246
- async def get_total_classes(self) -> TotalClasses:
247
- """Get the member's total classes. This is a simple object reflecting the total number of classes attended,
248
- both in-studio and OT Live.
249
-
250
- Returns:
251
- TotalClasses: The member's total classes.
252
- """
253
- data = await self._default_request("GET", "/mobile/v1/members/classes/summary")
254
- return TotalClasses(**data["data"])
235
+ return BodyCompositionList(data=data["data"])
255
236
 
256
237
  async def get_classes(
257
238
  self,
@@ -346,6 +327,16 @@ class Otf:
346
327
 
347
328
  return classes_list
348
329
 
330
+ async def get_total_classes(self) -> TotalClasses:
331
+ """Get the member's total classes. This is a simple object reflecting the total number of classes attended,
332
+ both in-studio and OT Live.
333
+
334
+ Returns:
335
+ TotalClasses: The member's total classes.
336
+ """
337
+ data = await self._default_request("GET", "/mobile/v1/members/classes/summary")
338
+ return TotalClasses(**data["data"])
339
+
349
340
  async def book_class(self, class_uuid: str) -> BookClass | typing.Any:
350
341
  """Book a class by class_uuid.
351
342
 
@@ -860,16 +851,15 @@ class Otf:
860
851
  res = await self._telemetry_request("GET", path, params=params)
861
852
  return TelemetryMaxHr(**res)
862
853
 
863
- async def get_telemetry(self, class_history_uuid: str, max_data_points: int = 0) -> Telemetry:
864
- """Get the telemetry for a class history.
854
+ async def get_telemetry(self, performance_summary_id: str, max_data_points: int = 120) -> Telemetry:
855
+ """Get the telemetry for a performance summary.
865
856
 
866
857
  This returns an object that contains the max heartrate, start/end bpm for each zone,
867
858
  and a list of telemetry items that contain the heartrate, splat points, calories, and timestamp.
868
859
 
869
860
  Args:
870
- class_history_uuid (str): The class history UUID.
871
- max_data_points (int): The max data points to use for the telemetry. Default is 0, which will attempt to\
872
- get the max data points from the workout. If the workout is not found, it will default to 120 data points.
861
+ performance_summary_id (str): The performance summary id.
862
+ max_data_points (int): The max data points to use for the telemetry. Default is 120.
873
863
 
874
864
  Returns:
875
865
  TelemetryItem: The telemetry for the class history.
@@ -877,30 +867,10 @@ class Otf:
877
867
  """
878
868
  path = "/v1/performance/summary"
879
869
 
880
- max_data_points = max_data_points or await self._get_max_data_points(class_history_uuid)
881
-
882
- params = {"classHistoryUuid": class_history_uuid, "maxDataPoints": max_data_points}
870
+ params = {"classHistoryUuid": performance_summary_id, "maxDataPoints": max_data_points}
883
871
  res = await self._telemetry_request("GET", path, params=params)
884
872
  return Telemetry(**res)
885
873
 
886
- async def _get_max_data_points(self, class_history_uuid: str) -> int:
887
- """Get the max data points to use for the telemetry.
888
-
889
- Attempts to get the amount of active time for the workout from the OT Live API. If the workout is not found,
890
- it will default to 120 data points. If it is found, it will calculate the amount of data points needed based on
891
- the active time. This should amount to a data point per 30 seconds, roughly.
892
-
893
- Args:
894
- class_history_uuid (str): The class history UUID.
895
-
896
- Returns:
897
- int: The max data points to use.
898
- """
899
- workouts = await self.get_workouts()
900
- workout = workouts.by_class_history_uuid.get(class_history_uuid)
901
- max_data_points = 120 if workout is None else ceil(active_time_to_data_points(workout.active_time))
902
- return max_data_points
903
-
904
874
  # the below do not return any data for me, so I can't test them
905
875
 
906
876
  async def _get_member_services(self, active_only: bool = True) -> typing.Any:
@@ -934,17 +904,3 @@ class Otf:
934
904
 
935
905
  data = self._default_request("GET", f"/member/wearables/{self._member_id}/wearable-daily", params=params)
936
906
  return data
937
-
938
- async def get_body_composition_list(self) -> BodyCompositionList:
939
- """Get the member's body composition list.
940
-
941
- Returns:
942
- Any: The member's body composition list.
943
- """
944
- data = await self._default_request("GET", f"/member/members/{self._member_uuid}/body-composition")
945
-
946
- return BodyCompositionList(data=data["data"])
947
-
948
-
949
- def active_time_to_data_points(active_time: int) -> float:
950
- return active_time / 60 * 2
@@ -63,7 +63,8 @@ class OtfCognito(Cognito):
63
63
  @device_key.setter
64
64
  def device_key(self, value: str | None):
65
65
  if not value:
66
- logger.info("Clearing device key")
66
+ if self._device_key:
67
+ logger.info("Clearing device key")
67
68
  self._device_key = value
68
69
  return
69
70
 
@@ -30,7 +30,6 @@ from .responses import (
30
30
  TelemetryHrHistory,
31
31
  TelemetryMaxHr,
32
32
  TotalClasses,
33
- WorkoutList,
34
33
  )
35
34
 
36
35
  __all__ = [
@@ -66,5 +65,4 @@ __all__ = [
66
65
  "TelemetryHrHistory",
67
66
  "TelemetryMaxHr",
68
67
  "TotalClasses",
69
- "WorkoutList",
70
68
  ]
@@ -1,14 +1,9 @@
1
1
  import inspect
2
2
  import typing
3
- from enum import Enum
4
- from typing import Any, ClassVar, TypeVar
3
+ from typing import ClassVar, TypeVar
5
4
 
6
5
  from box import Box
7
- from inflection import humanize
8
6
  from pydantic import BaseModel, ConfigDict
9
- from rich.style import Style
10
- from rich.styled import Styled
11
- from rich.table import Table
12
7
 
13
8
  if typing.TYPE_CHECKING:
14
9
  from pydantic.main import IncEx
@@ -138,50 +133,6 @@ class BetterDumperMixin:
138
133
  class OtfItemBase(BetterDumperMixin, BaseModel):
139
134
  model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True, extra="forbid")
140
135
 
141
- def convert_row_value_types(self, row: list[Any]) -> list[str]:
142
- for i, val in enumerate(row):
143
- if isinstance(val, bool):
144
- row[i] = str(val)
145
- continue
146
-
147
- if isinstance(val, Enum):
148
- row[i] = val.name
149
- continue
150
-
151
- if val is None:
152
- row[i] = ""
153
- continue
154
-
155
- row[i] = str(val)
156
-
157
- return row
158
-
159
- def get_style(self, is_selected: bool = False) -> Style:
160
- return Style(color="blue", bold=True) if is_selected else Style(color="white")
161
-
162
- def to_row(self, attributes: list[str], is_selected: bool = False) -> list[Styled]:
163
- style = self.get_style(is_selected)
164
-
165
- boxed_self = Box(self.model_dump(), box_dots=True)
166
- row = [boxed_self.get(attr, "") for attr in attributes]
167
- row = self.convert_row_value_types(row)
168
- styled = [Styled(cell, style=style) for cell in row]
169
-
170
- prefix = "> " if is_selected else " "
171
- styled.insert(0, Styled(prefix, style=style))
172
-
173
- return styled
174
-
175
- @property
176
- def sidebar_data(self) -> Table | None:
177
- return None
178
-
179
- @classmethod
180
- def attr_to_column_header(cls, attr: str) -> str:
181
- attr_map = {k: humanize(k) for k in cls.model_fields}
182
-
183
- return attr_map.get(attr, attr)
184
-
185
136
 
186
137
  class OtfListBase(BaseModel):
187
138
  model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True, extra="forbid")
@@ -191,18 +142,6 @@ class OtfListBase(BaseModel):
191
142
  def collection(self) -> list[OtfItemBase]:
192
143
  return getattr(self, self.collection_field)
193
144
 
194
- def to_table(self, columns: list[str]) -> Table:
195
- table = Table(expand=True, show_header=True, show_footer=False)
196
-
197
- table.add_column()
198
- for column in columns:
199
- table.add_column(OtfItemBase.attr_to_column_header(column))
200
-
201
- for item in self.collection:
202
- table.add_row(*item.to_row(columns))
203
-
204
- return table
205
-
206
145
  def to_json(self, **kwargs) -> str:
207
146
  kwargs.setdefault("indent", 4)
208
147
  kwargs.setdefault("exclude_none", True)
@@ -21,7 +21,6 @@ from .telemetry import Telemetry
21
21
  from .telemetry_hr_history import TelemetryHrHistory
22
22
  from .telemetry_max_hr import TelemetryMaxHr
23
23
  from .total_classes import TotalClasses
24
- from .workouts import WorkoutList
25
24
 
26
25
  __all__ = [
27
26
  "BodyCompositionList",
@@ -56,5 +55,4 @@ __all__ = [
56
55
  "TelemetryHrHistory",
57
56
  "TelemetryMaxHr",
58
57
  "TotalClasses",
59
- "WorkoutList",
60
58
  ]
@@ -4,9 +4,6 @@ from typing import ClassVar
4
4
 
5
5
  from inflection import humanize
6
6
  from pydantic import Field
7
- from rich.style import Style
8
- from rich.styled import Styled
9
- from rich.table import Table
10
7
 
11
8
  from otf_api.models.base import OtfItemBase, OtfListBase
12
9
  from otf_api.models.responses.classes import OtfClassTimeMixin
@@ -223,82 +220,7 @@ class Booking(OtfItemBase):
223
220
  def id_val(self) -> str:
224
221
  return self.class_booking_id
225
222
 
226
- @property
227
- def sidebar_data(self) -> Table:
228
- data = {
229
- "date": self.otf_class.date,
230
- "class_name": self.otf_class.name,
231
- "description": self.otf_class.description,
232
- "class_id": self.id_val,
233
- "studio_address": self.otf_class.studio.studio_location.physical_address,
234
- "coach_name": self.otf_class.coach.name,
235
- }
236
-
237
- table = Table(expand=True, show_header=False, show_footer=False)
238
- table.add_column("Key", style="cyan", ratio=1)
239
- table.add_column("Value", style="magenta", ratio=2)
240
-
241
- for key, value in data.items():
242
- if value is False:
243
- table.add_row(key, Styled(str(value), style="red"))
244
- else:
245
- table.add_row(key, str(value))
246
-
247
- return table
248
-
249
- def get_style(self, is_selected: bool = False) -> Style:
250
- style = super().get_style(is_selected)
251
- if self.status == BookingStatus.Cancelled:
252
- style = Style(color="red")
253
- elif self.status == BookingStatus.Waitlisted:
254
- style = Style(color="yellow")
255
- elif self.status == BookingStatus.CheckedIn and is_selected:
256
- style = Style(color="blue", strike=True)
257
- elif self.status == BookingStatus.CheckedIn:
258
- style = Style(color="grey58")
259
-
260
- return style
261
-
262
- @classmethod
263
- def attr_to_column_header(cls, attr: str) -> str:
264
- if attr.startswith("otf_class"):
265
- return OtfClass.attr_to_column_header(attr.split(".")[-1])
266
-
267
- attr_map = {k: humanize(k) for k in cls.model_fields}
268
- overrides = {
269
- "day_of_week": "Class DoW",
270
- "date": "Class Date",
271
- "time": "Class Time",
272
- "duration": "Class Duration",
273
- "name": "Class Name",
274
- "is_home_studio": "Home Studio",
275
- "is_booked": "Booked",
276
- }
277
-
278
- attr_map.update(overrides)
279
-
280
- return attr_map.get(attr, attr)
281
-
282
223
 
283
224
  class BookingList(OtfListBase):
284
225
  collection_field: ClassVar[str] = "bookings"
285
226
  bookings: list[Booking]
286
-
287
- @staticmethod
288
- def show_bookings_columns() -> list[str]:
289
- return [
290
- "otf_class.day_of_week",
291
- "otf_class.date",
292
- "otf_class.time",
293
- "otf_class.duration",
294
- "otf_class.name",
295
- "status",
296
- "otf_class.studio.studio_name",
297
- "is_home_studio",
298
- ]
299
-
300
- def to_table(self, columns: list[str] | None = None) -> Table:
301
- if not columns:
302
- columns = self.show_bookings_columns()
303
-
304
- return super().to_table(columns)
@@ -3,11 +3,7 @@ from enum import Enum
3
3
  from typing import ClassVar
4
4
 
5
5
  from humanize import precisedelta
6
- from inflection import humanize
7
6
  from pydantic import Field
8
- from rich.style import Style
9
- from rich.styled import Styled
10
- from rich.table import Table
11
7
 
12
8
  from otf_api.models.base import OtfItemBase, OtfListBase
13
9
 
@@ -176,80 +172,7 @@ class OtfClass(OtfItemBase, OtfClassTimeMixin):
176
172
  dow = self.starts_at_local.strftime("%A")
177
173
  return DoW.get_case_insensitive(dow)
178
174
 
179
- @property
180
- def sidebar_data(self) -> Table:
181
- data = {
182
- "class_date": self.date,
183
- "class_time": self.time.strip(),
184
- "class_name": self.name,
185
- "class_id": self.id_val,
186
- "available": self.has_availability,
187
- "waitlist_available": self.waitlist_available,
188
- "studio_address": self.studio.address.line1,
189
- "coach_name": self.coach.first_name,
190
- "waitlist_size": self.waitlist_size,
191
- "max_capacity": self.max_capacity,
192
- }
193
-
194
- if not self.full:
195
- del data["waitlist_available"]
196
- del data["waitlist_size"]
197
-
198
- table = Table(expand=True, show_header=False, show_footer=False)
199
- table.add_column("Key", style="cyan", ratio=1)
200
- table.add_column("Value", style="magenta", ratio=2)
201
-
202
- for key, value in data.items():
203
- if value is False:
204
- table.add_row(key, Styled(str(value), style="red"))
205
- else:
206
- table.add_row(key, str(value))
207
-
208
- return table
209
-
210
- def get_style(self, is_selected: bool = False) -> Style:
211
- style = super().get_style(is_selected)
212
- if self.is_booked:
213
- style = Style(color="grey58")
214
- return style
215
-
216
- @classmethod
217
- def attr_to_column_header(cls, attr: str) -> str:
218
- attr_map = {k: humanize(k) for k in cls.model_fields}
219
- overrides = {
220
- "day_of_week": "Class DoW",
221
- "date": "Class Date",
222
- "time": "Class Time",
223
- "duration": "Class Duration",
224
- "name": "Class Name",
225
- "is_home_studio": "Home Studio",
226
- "is_booked": "Booked",
227
- }
228
-
229
- attr_map.update(overrides)
230
-
231
- return attr_map.get(attr, attr)
232
-
233
175
 
234
176
  class OtfClassList(OtfListBase):
235
177
  collection_field: ClassVar[str] = "classes"
236
178
  classes: list[OtfClass]
237
-
238
- @staticmethod
239
- def book_class_columns() -> list[str]:
240
- return [
241
- "day_of_week",
242
- "date",
243
- "time",
244
- "duration",
245
- "name",
246
- "studio.name",
247
- "is_home_studio",
248
- "is_booked",
249
- ]
250
-
251
- def to_table(self, columns: list[str] | None = None) -> Table:
252
- if not columns:
253
- columns = self.book_class_columns()
254
-
255
- return super().to_table(columns)
@@ -33,7 +33,7 @@ class Studio(OtfItemBase):
33
33
  class Class(OtfItemBase):
34
34
  ot_base_class_uuid: str | None = None
35
35
  starts_at_local: str
36
- name: str
36
+ name: str | None = None
37
37
  coach: Coach
38
38
  studio: Studio
39
39
 
@@ -56,7 +56,7 @@ class Ratings(OtfItemBase):
56
56
 
57
57
 
58
58
  class PerformanceSummaryEntry(OtfItemBase):
59
- performance_summary_id: str = Field(..., alias="id")
59
+ id: str = Field(..., alias="id")
60
60
  details: Details
61
61
  ratable: bool
62
62
  otf_class: Class = Field(..., alias="class")
@@ -1,4 +0,0 @@
1
- from otf_api.cli.app import base_app
2
- from otf_api.cli.bookings import bookings_app, classes_app
3
-
4
- __all__ = ["base_app", "bookings_app", "classes_app"]
@@ -1,60 +0,0 @@
1
- import functools
2
- import inspect
3
- import traceback
4
- from collections.abc import Awaitable, Callable
5
- from typing import Any, NoReturn, ParamSpec, TypeGuard, TypeVar
6
-
7
- import typer
8
- from click.exceptions import ClickException
9
-
10
- T = TypeVar("T")
11
- P = ParamSpec("P")
12
- R = TypeVar("R")
13
-
14
-
15
- def is_async_fn(func: Callable[P, R] | Callable[P, Awaitable[R]]) -> TypeGuard[Callable[P, Awaitable[R]]]:
16
- """
17
- Returns `True` if a function returns a coroutine.
18
-
19
- See https://github.com/microsoft/pyright/issues/2142 for an example use
20
- """
21
- while hasattr(func, "__wrapped__"):
22
- func = func.__wrapped__
23
-
24
- return inspect.iscoroutinefunction(func)
25
-
26
-
27
- def exit_with_error(message: Any, code: int = 1, **kwargs: Any) -> NoReturn:
28
- """
29
- Utility to print a stylized error message and exit with a non-zero code
30
- """
31
- from otf_api.cli.app import base_app
32
-
33
- kwargs.setdefault("style", "red")
34
- base_app.console.print(message, **kwargs)
35
- raise typer.Exit(code)
36
-
37
-
38
- def exit_with_success(message: Any, **kwargs: Any) -> NoReturn:
39
- """
40
- Utility to print a stylized success message and exit with a zero code
41
- """
42
- from otf_api.cli.app import base_app
43
-
44
- kwargs.setdefault("style", "green")
45
- base_app.console.print(message, **kwargs)
46
- raise typer.Exit(0)
47
-
48
-
49
- def with_cli_exception_handling(fn: Callable[[Any], Any]) -> Callable[[Any], Any]:
50
- @functools.wraps(fn)
51
- def wrapper(*args: Any, **kwargs: Any) -> Any | None:
52
- try:
53
- return fn(*args, **kwargs)
54
- except (typer.Exit, typer.Abort, ClickException):
55
- raise # Do not capture click or typer exceptions
56
- except Exception:
57
- traceback.print_exc()
58
- exit_with_error("An exception occurred.")
59
-
60
- return wrapper