docs: More comments on files
This commit is contained in:
@@ -14,15 +14,19 @@ if __name__ == "__main__":
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Reduce the verbosity of the requests library's logging
|
||||||
logging.getLogger("requests").setLevel(logging.WARNING)
|
logging.getLogger("requests").setLevel(logging.WARNING)
|
||||||
logging.info("Logging enhanced with request library noise reduction")
|
logging.info("Logging enhanced with request library noise reduction")
|
||||||
|
|
||||||
# Start the main runner
|
# Create an instance of the CrossFitBooker class
|
||||||
booker = CrossFitBooker()
|
booker = CrossFitBooker()
|
||||||
|
|
||||||
|
# Attempt to log in to the CrossFit booking system
|
||||||
if not booker.login():
|
if not booker.login():
|
||||||
|
# If login fails, log the error and exit the script
|
||||||
logging.error("Failed to login - Traceback: %s", traceback.format_exc())
|
logging.error("Failed to login - Traceback: %s", traceback.format_exc())
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Start continuous booking loop
|
# Start the continuous booking loop
|
||||||
booker.run()
|
booker.run()
|
||||||
logging.info("Script completed")
|
logging.info("Script completed")
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ class SessionConfig:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_preferred_sessions():
|
def load_preferred_sessions(config_file="preferred_sessions.json"):
|
||||||
"""
|
"""
|
||||||
Load preferred sessions from a JSON file.
|
Load preferred sessions from a JSON file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config_file (str): Path to the JSON file containing preferred sessions.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List[Tuple[int, str, str]]: List of preferred sessions in the format
|
List[Tuple[int, str, str]]: List of preferred sessions in the format
|
||||||
(day_of_week, start_time, session_name_contains)
|
(day_of_week, start_time, session_name_contains)
|
||||||
@@ -19,23 +22,36 @@ class SessionConfig:
|
|||||||
preferred_sessions = []
|
preferred_sessions = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("preferred_sessions.json", "r") as f:
|
# Attempt to open and read the JSON file
|
||||||
|
with open(config_file, "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
|
# Validate and parse each item in the JSON data
|
||||||
for item in data:
|
for item in data:
|
||||||
day_of_week = item.get("day_of_week", 0)
|
day_of_week = item.get("day_of_week", 0) # Default to Monday if not specified
|
||||||
start_time = item.get("start_time", "00:00")
|
start_time = item.get("start_time", "00:00") # Default to midnight if not specified
|
||||||
session_name_contains = item.get("session_name_contains", "")
|
session_name_contains = item.get("session_name_contains", "") # Default to empty string if not specified
|
||||||
|
|
||||||
|
# Append the parsed session to the list
|
||||||
preferred_sessions.append((day_of_week, start_time, session_name_contains))
|
preferred_sessions.append((day_of_week, start_time, session_name_contains))
|
||||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
|
||||||
logging.warning(f"Failed to load preferred sessions from file: {str(e)}")
|
except FileNotFoundError:
|
||||||
# Fall back to default hardcoded sessions
|
# Log a warning if the file is not found
|
||||||
# preferred_sessions = [
|
logging.warning(f"Configuration file '{config_file}' not found. Falling back to default settings.")
|
||||||
# (2, "18:30", "CONDITIONING"), # Wednesday 18:30 CONDITIONING
|
|
||||||
# (4, "17:00", "WEIGHTLIFTING"), # Friday 17:00 WEIGHTLIFTING
|
except json.JSONDecodeError:
|
||||||
# (5, "12:30", "HYROX"), # Saturday 12:30 HYROX
|
# Log a warning if the file is not a valid JSON
|
||||||
# ]
|
logging.warning(f"Failed to decode JSON from file '{config_file}'. Falling back to default settings.")
|
||||||
|
|
||||||
|
# Fallback to default hardcoded sessions if no valid sessions were loaded
|
||||||
|
if not preferred_sessions:
|
||||||
|
preferred_sessions = [
|
||||||
|
(2, "18:30", "CONDITIONING"), # Wednesday 18:30 CONDITIONING
|
||||||
|
(4, "17:00", "WEIGHTLIFTING"), # Friday 17:00 WEIGHTLIFTING
|
||||||
|
(5, "12:30", "HYROX"), # Saturday 12:30 HYROX
|
||||||
|
]
|
||||||
|
|
||||||
return preferred_sessions
|
return preferred_sessions
|
||||||
|
|
||||||
# Load preferred sessions using the SessionConfig class
|
# Load preferred sessions using the SessionConfig class
|
||||||
PREFERRED_SESSIONS = SessionConfig.load_preferred_sessions()
|
PREFERRED_SESSIONS = SessionConfig.load_preferred_sessions()
|
||||||
|
|||||||
Reference in New Issue
Block a user