pysportbot 0.0.6__tar.gz → 0.0.7__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.
- {pysportbot-0.0.6 → pysportbot-0.0.7}/PKG-INFO +2 -2
- {pysportbot-0.0.6 → pysportbot-0.0.7}/README.md +1 -1
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pyproject.toml +1 -1
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/service/__main__.py +5 -7
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/service/booking.py +17 -16
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/service/service.py +8 -8
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/utils/errors.py +1 -5
- {pysportbot-0.0.6 → pysportbot-0.0.7}/LICENSE +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/__init__.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/activities.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/authenticator.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/bookings.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/centres.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/endpoints.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/service/__init__.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/service/config_loader.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/service/config_validator.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/service/scheduling.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/session.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/utils/__init__.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/utils/logger.py +0 -0
- {pysportbot-0.0.6 → pysportbot-0.0.7}/pysportbot/utils/time.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pysportbot
|
3
|
-
Version: 0.0.
|
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
|
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
|
|
@@ -98,7 +98,7 @@ python -m pysportbot.service --help
|
|
98
98
|
```
|
99
99
|
Currently supported options include
|
100
100
|
1. ```--retry-attempts``` sets the number of retries attempted in case a booking attempt fails
|
101
|
-
2. ```--retry-delay
|
101
|
+
2. ```--retry-delay``` sets the delay in seconds between retries booking retries
|
102
102
|
3. ```--time-zone``` sets the time zone for the service (e.g. Europe/Madrid)
|
103
103
|
4. ```--log-level``` sets the log-level of the service (e.g. DEBUG, INFO, WARNING, ERROR)
|
104
104
|
|
@@ -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("--
|
14
|
-
parser.add_argument("--retry-attempts", type=int, default=3, help="Number of retry attempts for
|
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
|
-
|
23
|
+
booking_delay=args.booking_delay,
|
26
24
|
retry_attempts=args.retry_attempts,
|
27
|
-
|
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
|
-
|
47
|
+
booking_delay: int,
|
48
48
|
retry_attempts: int = 1,
|
49
|
-
|
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
|
-
|
60
|
+
booking_delay (int): Delay before attempting booking.
|
61
61
|
retry_attempts (int): Number of retry attempts.
|
62
|
-
|
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 {
|
93
|
-
time.sleep(
|
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
|
100
|
+
def schedule_bookings(
|
104
101
|
bot: SportBot,
|
105
102
|
classes: List[Dict[str, Any]],
|
106
103
|
booking_execution: str,
|
107
|
-
|
104
|
+
booking_delay: int,
|
108
105
|
retry_attempts: int,
|
109
|
-
|
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
|
-
|
117
|
+
booking_delay (int): Delay before each booking attempt.
|
121
118
|
retry_attempts (int): Number of retry attempts.
|
122
|
-
|
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
|
-
|
142
|
+
booking_delay,
|
142
143
|
retry_attempts,
|
143
|
-
|
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
|
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
|
-
|
12
|
+
booking_delay: int,
|
13
13
|
retry_attempts: int,
|
14
|
-
|
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
|
-
|
23
|
+
booking_delay (int): Delay before each booking attempt.
|
24
24
|
retry_attempts (int): Number of retry attempts.
|
25
|
-
|
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
|
-
|
48
|
+
schedule_bookings(
|
49
49
|
bot,
|
50
50
|
config["classes"],
|
51
51
|
config["booking_execution"],
|
52
|
-
|
52
|
+
booking_delay,
|
53
53
|
retry_attempts,
|
54
|
-
|
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'
|
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:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|