pysportbot 0.0.6__py3-none-any.whl → 0.0.7__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.
@@ -10,11 +10,9 @@ from .service import run_service
10
10
  def main() -> None:
11
11
  parser = argparse.ArgumentParser(description="Run the pysportbot as a service.")
12
12
  parser.add_argument("--config", type=str, required=True, help="Path to the JSON configuration file.")
13
- parser.add_argument("--offset-seconds", type=int, default=5, help="Time offset in seconds before booking.")
14
- parser.add_argument("--retry-attempts", type=int, default=3, help="Number of retry attempts for weekly bookings.")
15
- parser.add_argument(
16
- "--retry-delay-minutes", type=int, default=1, help="Delay in minutes between retries for weekly bookings."
17
- )
13
+ parser.add_argument("--booking-delay", type=int, default=5, help="Global booking delay in seconds before booking.")
14
+ parser.add_argument("--retry-attempts", type=int, default=3, help="Number of retry attempts for bookings.")
15
+ parser.add_argument("--retry-delay", type=int, default=30, help="Delay in seconds between retries for bookings.")
18
16
  parser.add_argument("--time-zone", type=str, default="Europe/Madrid", help="Timezone for the service.")
19
17
  parser.add_argument("--log-level", type=str, default="INFO", help="Logging level for the service.")
20
18
  args = parser.parse_args()
@@ -22,9 +20,9 @@ def main() -> None:
22
20
  config: Dict[str, Any] = load_config(args.config)
23
21
  run_service(
24
22
  config,
25
- offset_seconds=args.offset_seconds,
23
+ booking_delay=args.booking_delay,
26
24
  retry_attempts=args.retry_attempts,
27
- retry_delay_minutes=args.retry_delay_minutes,
25
+ retry_delay=args.retry_delay,
28
26
  time_zone=args.time_zone,
29
27
  log_level=args.log_level,
30
28
  )
@@ -44,9 +44,9 @@ def attempt_booking(
44
44
  activity: str,
45
45
  class_day: str,
46
46
  class_time: str,
47
- offset_seconds: int,
47
+ booking_delay: int,
48
48
  retry_attempts: int = 1,
49
- retry_delay_minutes: int = 0,
49
+ retry_delay: int = 0,
50
50
  time_zone: str = "Europe/Madrid",
51
51
  ) -> None:
52
52
  """
@@ -57,9 +57,9 @@ def attempt_booking(
57
57
  activity (str): Activity name.
58
58
  class_day (str): Day of the class.
59
59
  class_time (str): Time of the class.
60
- offset_seconds (int): Delay before attempting booking.
60
+ booking_delay (int): Delay before attempting booking.
61
61
  retry_attempts (int): Number of retry attempts.
62
- retry_delay_minutes (int): Delay between retries.
62
+ retry_delay (int): Delay between retries.
63
63
  time_zone (str): Time zone for execution.
64
64
  """
65
65
  for attempt_num in range(1, retry_attempts + 1):
@@ -73,9 +73,6 @@ def attempt_booking(
73
73
  if matching_slots.empty:
74
74
  _raise_no_matching_slots_error(activity, class_time, booking_date)
75
75
 
76
- logger.info(f"Waiting {offset_seconds} seconds before attempting booking.")
77
- time.sleep(offset_seconds)
78
-
79
76
  slot_id = matching_slots.iloc[0]["start_timestamp"]
80
77
  logger.info(f"Attempting to book '{activity}' at {slot_id} (Attempt {attempt_num}/{retry_attempts}).")
81
78
  bot.book(activity=activity, start_time=slot_id)
@@ -89,8 +86,8 @@ def attempt_booking(
89
86
  return
90
87
 
91
88
  if attempt_num < retry_attempts:
92
- logger.info(f"Retrying in {retry_delay_minutes} minutes...")
93
- time.sleep(retry_delay_minutes * 60)
89
+ logger.info(f"Retrying in {retry_delay} seconds...")
90
+ time.sleep(retry_delay)
94
91
  else:
95
92
  # If the booking attempt succeeds, log and exit
96
93
  logger.info(f"Successfully booked '{activity}' at {slot_id}.")
@@ -100,13 +97,13 @@ def attempt_booking(
100
97
  logger.error(f"Failed to book '{activity}' after {retry_attempts} attempts.")
101
98
 
102
99
 
103
- def schedule_bookings_parallel(
100
+ def schedule_bookings(
104
101
  bot: SportBot,
105
102
  classes: List[Dict[str, Any]],
106
103
  booking_execution: str,
107
- offset_seconds: int,
104
+ booking_delay: int,
108
105
  retry_attempts: int,
109
- retry_delay_minutes: int,
106
+ retry_delay: int,
110
107
  time_zone: str,
111
108
  max_threads: int,
112
109
  ) -> None:
@@ -117,9 +114,9 @@ def schedule_bookings_parallel(
117
114
  bot (SportBot): The SportBot instance.
118
115
  classes (list): List of class configurations.
119
116
  booking_execution (str): Global execution time for all bookings.
120
- offset_seconds (int): Delay before each booking attempt.
117
+ booking_delay (int): Delay before each booking attempt.
121
118
  retry_attempts (int): Number of retry attempts.
122
- retry_delay_minutes (int): Delay between retries.
119
+ retry_delay (int): Delay between retries.
123
120
  time_zone (str): Timezone for booking.
124
121
  max_threads (int): Maximum number of threads to use.
125
122
  """
@@ -130,6 +127,10 @@ def schedule_bookings_parallel(
130
127
  # Wait globally before starting bookings
131
128
  wait_for_execution(booking_execution, time_zone)
132
129
 
130
+ # Global booking delay
131
+ logger.info(f"Waiting {booking_delay} seconds before attempting booking.")
132
+ time.sleep(booking_delay)
133
+
133
134
  with ThreadPoolExecutor(max_workers=max_threads) as executor:
134
135
  future_to_class = {
135
136
  executor.submit(
@@ -138,9 +139,9 @@ def schedule_bookings_parallel(
138
139
  cls["activity"],
139
140
  cls["class_day"],
140
141
  cls["class_time"],
141
- offset_seconds,
142
+ booking_delay,
142
143
  retry_attempts,
143
- retry_delay_minutes,
144
+ retry_delay,
144
145
  time_zone,
145
146
  ): cls
146
147
  for cls in classes
@@ -2,16 +2,16 @@ import os
2
2
  from typing import Any, Dict
3
3
 
4
4
  from pysportbot import SportBot
5
- from pysportbot.service.booking import schedule_bookings_parallel
5
+ from pysportbot.service.booking import schedule_bookings
6
6
  from pysportbot.service.config_validator import validate_activities, validate_config
7
7
  from pysportbot.utils.logger import get_logger
8
8
 
9
9
 
10
10
  def run_service(
11
11
  config: Dict[str, Any],
12
- offset_seconds: int,
12
+ booking_delay: int,
13
13
  retry_attempts: int,
14
- retry_delay_minutes: int,
14
+ retry_delay: int,
15
15
  time_zone: str = "Europe/Madrid",
16
16
  log_level: str = "INFO",
17
17
  ) -> None:
@@ -20,9 +20,9 @@ def run_service(
20
20
 
21
21
  Args:
22
22
  config (dict): Configuration dictionary for booking service.
23
- offset_seconds (int): Delay before each booking attempt.
23
+ booking_delay (int): Delay before each booking attempt.
24
24
  retry_attempts (int): Number of retry attempts.
25
- retry_delay_minutes (int): Delay between retry attempts in minutes.
25
+ retry_delay (int): Delay between retry attempts in minutes.
26
26
  time_zone (str): Time zone for the booking.
27
27
  log_level (str): Logging level for the service.
28
28
  """
@@ -45,13 +45,13 @@ def run_service(
45
45
  logger.info(f"Using up to {max_threads} threads for booking {len(config['classes'])} activities.")
46
46
 
47
47
  # Schedule bookings in parallel
48
- schedule_bookings_parallel(
48
+ schedule_bookings(
49
49
  bot,
50
50
  config["classes"],
51
51
  config["booking_execution"],
52
- offset_seconds,
52
+ booking_delay,
53
53
  retry_attempts,
54
- retry_delay_minutes,
54
+ retry_delay,
55
55
  time_zone,
56
56
  max_threads,
57
57
  )
@@ -20,11 +20,7 @@ class ErrorMessages:
20
20
 
21
21
  @staticmethod
22
22
  def invalid_class_definition() -> str:
23
- return "Each class must include 'activity', 'class_day', " "'class_time', 'booking_execution', and 'weekly'."
24
-
25
- @staticmethod
26
- def invalid_weekly_now() -> str:
27
- return "Invalid combination: cannot use weekly=True with booking_execution='now'."
23
+ return "Each class must include 'activity', 'class_day', " "'class_time'"
28
24
 
29
25
  @staticmethod
30
26
  def invalid_booking_execution_format() -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pysportbot
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: A python-based bot for automatic resasports slot booking
5
5
  Home-page: https://github.com/jbeirer/resasports-bot
6
6
  Author: Joshua Falco Beirer
@@ -119,7 +119,7 @@ python -m pysportbot.service --help
119
119
  ```
120
120
  Currently supported options include
121
121
  1. ```--retry-attempts``` sets the number of retries attempted in case a booking attempt fails
122
- 2. ```--retry-delay-minutes``` sets the delay in minutes between retries for weekly bookings
122
+ 2. ```--retry-delay``` sets the delay in seconds between retries booking retries
123
123
  3. ```--time-zone``` sets the time zone for the service (e.g. Europe/Madrid)
124
124
  4. ```--log-level``` sets the log-level of the service (e.g. DEBUG, INFO, WARNING, ERROR)
125
125
 
@@ -5,18 +5,18 @@ pysportbot/bookings.py,sha256=vJ0kw74qyirZlbQ7M9XqlKtRoGzuHR0_t6-zUdgldkI,3123
5
5
  pysportbot/centres.py,sha256=FTK-tXUOxiJvLCHP6Bk9XEQKODQZOwwkYLlioSJPBEk,3399
6
6
  pysportbot/endpoints.py,sha256=ANh5JAbdzyZQ-i4ODrhYlskPpU1gkBrw9UhMC7kRSvU,1353
7
7
  pysportbot/service/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- pysportbot/service/__main__.py,sha256=PSaqYZ8wWlmFT0_taeOA2NLZfm9fIOy6MBhrv_IPSP4,1319
9
- pysportbot/service/booking.py,sha256=bjPb9BLF7XOhFnr1ZArxUHNO6-10yM1z-3S5-ZFpXjQ,5713
8
+ pysportbot/service/__main__.py,sha256=R03cbuus-BZ_dgdga94zqKblEkxJPuGuOP1JIz5Deyo,1274
9
+ pysportbot/service/booking.py,sha256=88sZLzX72m7vQXhJdPyiQlZXoi552dK7CCLywbrBYYE,5647
10
10
  pysportbot/service/config_loader.py,sha256=elNNwcC7kwc0lmRqj95hAA50qSmLelWv5G2E62tDxP0,185
11
11
  pysportbot/service/config_validator.py,sha256=ce7p-LgPtvWnTYvpyUEE60627DHHzx5mFhEI9hDNB-4,2621
12
12
  pysportbot/service/scheduling.py,sha256=bwqbiQQ9y4ss4UXZkWuOVCgCa9XlZt1n4TT_8z9bD7M,1973
13
- pysportbot/service/service.py,sha256=_LR7rJ4GAgp4saSFREiSJCm4GzzEor6ZYkIkuAq7PLM,1866
13
+ pysportbot/service/service.py,sha256=Lwy5OTLeR2kneZZ1I3wCw6P4DItmN5Ih6ADSbZHU38M,1821
14
14
  pysportbot/session.py,sha256=pTQrz3bGzLYBtzVOgKv04l4UXDSgtA3Infn368bjg5I,1529
15
15
  pysportbot/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- pysportbot/utils/errors.py,sha256=sUSs04yr_OmZeTywi1fzPsjVjkLd5iTpXlzlQqNKmgQ,5162
16
+ pysportbot/utils/errors.py,sha256=mpTeKjOUIxJbOqL6A6apdMb7Cpto86DkrKHWfROXjMc,4979
17
17
  pysportbot/utils/logger.py,sha256=38rB0M6KPlelXPcgXPSEhXB36-_ZTERLJAQ8DRYIOTM,5189
18
18
  pysportbot/utils/time.py,sha256=VZSW8AxFIoFD5ZSmLUPcwawp6PmpkcxNjP3Db-Hl_fw,1244
19
- pysportbot-0.0.6.dist-info/LICENSE,sha256=6ov3DypdEVYpp2pn_B1MniKWO5C9iDA4O6PGcbork6c,1077
20
- pysportbot-0.0.6.dist-info/METADATA,sha256=lECBuUu6DaV2CiVXWwHpmz1b--lL7DhxwpOsrXTITKU,4904
21
- pysportbot-0.0.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
22
- pysportbot-0.0.6.dist-info/RECORD,,
19
+ pysportbot-0.0.7.dist-info/LICENSE,sha256=6ov3DypdEVYpp2pn_B1MniKWO5C9iDA4O6PGcbork6c,1077
20
+ pysportbot-0.0.7.dist-info/METADATA,sha256=rMxYNWwtB0qF_NHV4lDDXccasyi4LE8Ziuh6jO6wAxI,4892
21
+ pysportbot-0.0.7.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
22
+ pysportbot-0.0.7.dist-info/RECORD,,