A lot of features #1
@@ -15,7 +15,7 @@ from dateutil.parser import parse
|
|||||||
import pytz
|
import pytz
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from typing import List, Dict, Optional
|
from typing import List, Dict, Optional, Any
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
@@ -474,23 +474,34 @@ class CrossFitBooker:
|
|||||||
logging.error("Authentication failed - exiting program")
|
logging.error("Authentication failed - exiting program")
|
||||||
return
|
return
|
||||||
|
|
||||||
while True:
|
try:
|
||||||
try:
|
while True:
|
||||||
current_time: datetime = datetime.now(tz)
|
try:
|
||||||
logging.info(f"Current time: {current_time}")
|
current_time: datetime = datetime.now(tz)
|
||||||
|
logging.info(f"Current time: {current_time}")
|
||||||
|
|
||||||
# Run booking cycle at the target time or if it's a test, with optimized checking
|
# Run booking cycle at the target time or if it's a test, with optimized checking
|
||||||
if current_time.strftime("%H:%M") == TARGET_RESERVATION_TIME:
|
if current_time.strftime("%H:%M") == TARGET_RESERVATION_TIME:
|
||||||
self.run_booking_cycle(current_time)
|
self.run_booking_cycle(current_time)
|
||||||
# Wait until the next booking window
|
# Wait until the next booking window
|
||||||
wait_until = current_time + timedelta(minutes=60)
|
wait_until = current_time + timedelta(minutes=60)
|
||||||
time.sleep((wait_until - current_time).total_seconds())
|
time.sleep((wait_until - current_time).total_seconds())
|
||||||
else:
|
else:
|
||||||
# Check again in 5 minutes
|
# Check again in 5 minutes
|
||||||
time.sleep(300)
|
time.sleep(300)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Unexpected error in booking cycle: {str(e)} - Traceback: {traceback.format_exc()}")
|
logging.error(f"Unexpected error in booking cycle: {str(e)} - Traceback: {traceback.format_exc()}")
|
||||||
time.sleep(60) # Wait before retrying after error
|
time.sleep(60) # Wait before retrying after error
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
self.quit()
|
||||||
|
|
||||||
|
def quit(self) -> None:
|
||||||
|
"""
|
||||||
|
Clean up resources and exit the script.
|
||||||
|
"""
|
||||||
|
logging.info("Script interrupted by user. Quitting...")
|
||||||
|
# Add any cleanup code here
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -501,3 +512,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Start continuous booking loop
|
# Start continuous booking loop
|
||||||
booker.run()
|
booker.run()
|
||||||
|
logging.info("Script completed")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user