pysportbot 0.0.13__py3-none-any.whl → 0.0.14__py3-none-any.whl

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.
pysportbot/activities.py CHANGED
@@ -32,13 +32,27 @@ class Activities:
32
32
  """
33
33
  logger.info("Fetching activities...")
34
34
  response = self.session.post(Endpoints.ACTIVITIES, headers=self.headers)
35
+
35
36
  if response.status_code != 200:
36
37
  error_msg = ErrorMessages.failed_fetch("activities")
37
38
  logger.error(error_msg)
38
39
  raise RuntimeError(error_msg)
40
+
41
+ try:
42
+ activities = response.json().get("activities", {})
43
+ except json.JSONDecodeError as err:
44
+ error_msg = "Invalid JSON response while fetching activities."
45
+ logger.error(error_msg)
46
+ raise RuntimeError(error_msg) from err
47
+
48
+ if not activities:
49
+ logger.warning("No activities found in the response.")
50
+
51
+ df_activities = pd.DataFrame.from_dict(activities, orient="index")
52
+ df_activities.index = df_activities.index.astype(int) # Ensure index is integer for consistency
53
+
39
54
  logger.info("Activities fetched successfully.")
40
- activities = json.loads(response.content.decode("utf-8"))["activities"]
41
- return pd.DataFrame.from_dict(activities, orient="index")
55
+ return df_activities
42
56
 
43
57
  def daily_slots(self, df_activities: DataFrame, activity_name: str, day: str) -> DataFrame:
44
58
  """
@@ -67,9 +81,10 @@ class Activities:
67
81
  logger.error(error_msg)
68
82
  raise ValueError(error_msg)
69
83
 
70
- # Extract activity ID
71
- activity_id = str(activity_match.id_activity.iloc[0])
72
- id_category_activity = df_activities.loc[activity_id].activityCategoryId
84
+ # Extract activity ID and category ID
85
+ # Ensures activity_id is an integer
86
+ activity_id = activity_match.index[0]
87
+ id_category_activity = activity_match.at[activity_id, "activityCategoryId"]
73
88
 
74
89
  # Get Unix timestamp bounds for the day
75
90
  unix_day_bounds = get_unix_day_bounds(day)
@@ -81,12 +96,19 @@ class Activities:
81
96
  "end": unix_day_bounds[1],
82
97
  }
83
98
  response = self.session.get(Endpoints.SLOTS, headers=self.headers, params=params)
99
+
84
100
  if response.status_code != 200:
85
101
  error_msg = ErrorMessages.failed_fetch("slots")
86
102
  logger.error(error_msg)
87
103
  raise RuntimeError(error_msg)
88
104
 
89
- slots = json.loads(response.content.decode("utf-8"))
105
+ try:
106
+ slots = response.json()
107
+ except json.JSONDecodeError as err:
108
+ error_msg = "Invalid JSON response while fetching slots."
109
+ logger.error(error_msg)
110
+ raise RuntimeError(error_msg) from err
111
+
90
112
  if not slots:
91
113
  warning_msg = ErrorMessages.no_slots(activity_name, day)
92
114
  logger.warning(warning_msg)
@@ -110,10 +132,12 @@ class Activities:
110
132
  "trainer",
111
133
  ]
112
134
  df_slots = pd.DataFrame(slots)
113
- df_slots = df_slots[df_slots.columns.intersection(columns)] # Ensure no KeyError
135
+
136
+ # Ensure only desired columns are selected without KeyError
137
+ df_slots = df_slots.loc[:, df_slots.columns.intersection(columns)]
114
138
 
115
139
  # Only select rows of the specified activity
116
- df_slots = df_slots[df_slots.id_activity == activity_id]
140
+ df_slots = df_slots[df_slots["id_activity"] == activity_id]
117
141
  if df_slots.empty:
118
142
  warning_msg = ErrorMessages.no_matching_slots(activity_name, day)
119
143
  logger.warning(warning_msg)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pysportbot
3
- Version: 0.0.13
3
+ Version: 0.0.14
4
4
  Summary: A python-based bot for automatic resasports slot booking
5
5
  Author: Joshua Falco Beirer
6
6
  Author-email: jbeirer@cern.ch
@@ -1,5 +1,5 @@
1
1
  pysportbot/__init__.py,sha256=tZwOIuLO1-a3d4KKA5nNfXfN6PjJxem_hxyuff9utk4,6425
2
- pysportbot/activities.py,sha256=Aq8l570sxqEAKplsEMVkuDoPJJjoaZlIwPh6i64_SJ8,4252
2
+ pysportbot/activities.py,sha256=MATA0feSsDSoeFnHa4Y_dLv3gw4P6MFg-0kAEybqVIY,4991
3
3
  pysportbot/authenticator.py,sha256=t_5x9anmsfh0SwpN9JSemzqKv72Hwt__Q8mQBowIOIo,5183
4
4
  pysportbot/bookings.py,sha256=W91AYGPu0sCpGliuiVdlENsoGYzH8P6v-SyKisbSb7g,3127
5
5
  pysportbot/centres.py,sha256=FTK-tXUOxiJvLCHP6Bk9XEQKODQZOwwkYLlioSJPBEk,3399
@@ -17,7 +17,7 @@ pysportbot/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
17
17
  pysportbot/utils/errors.py,sha256=IRarfGtk1tETxUGAhPAIbeits_u2tJvVCGTtkHIdYFQ,5146
18
18
  pysportbot/utils/logger.py,sha256=ANayMEeeAIVGKvITAxOFm2EdCbzBBTpNywuytAr4Z90,5366
19
19
  pysportbot/utils/time.py,sha256=VZSW8AxFIoFD5ZSmLUPcwawp6PmpkcxNjP3Db-Hl_fw,1244
20
- pysportbot-0.0.13.dist-info/LICENSE,sha256=6ov3DypdEVYpp2pn_B1MniKWO5C9iDA4O6PGcbork6c,1077
21
- pysportbot-0.0.13.dist-info/METADATA,sha256=ZksqiMoatQ6qOYaKy0QWGj_E1lUkWxx6ly4fVCHFhXM,7837
22
- pysportbot-0.0.13.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
23
- pysportbot-0.0.13.dist-info/RECORD,,
20
+ pysportbot-0.0.14.dist-info/LICENSE,sha256=6ov3DypdEVYpp2pn_B1MniKWO5C9iDA4O6PGcbork6c,1077
21
+ pysportbot-0.0.14.dist-info/METADATA,sha256=aUx264Y6n5fGY4GvpK0tClB03Gm_XyJd0cBboTWzJ1c,7837
22
+ pysportbot-0.0.14.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
23
+ pysportbot-0.0.14.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.0.0
2
+ Generator: poetry-core 2.0.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any