anny-booking-automation/main.py
b267a 358cb45a85 Trying new system.
New approach: pipeline will trigger BEFORE midnight, script waits till midnight and then immediately reserves the library space.
This hopefully improves the speed and the success-rate.
2025-08-04 19:54:56 +02:00

44 lines
1.1 KiB
Python

import datetime
import os
import time
from dotenv import load_dotenv
from auth.session import AnnySession
from booking.client import BookingClient
from utils.helpers import get_future_datetime
import pytz
def main():
load_dotenv('.env', override=True)
username = os.getenv("USERNAME")
password = os.getenv("PASSWORD")
start_time = datetime.datetime.now(pytz.timezone('Europe/Berlin'))
if not username or not password:
print("❌ Missing USERNAME or PASSWORD in .env")
return
session = AnnySession(username, password)
cookies = session.login()
if not cookies:
return
booking = BookingClient(cookies)
while start_time.day == datetime.datetime.now(pytz.timezone('Europe/Berlin')).day:
time.sleep(1)
start = get_future_datetime(hour="13:00:00")
end = get_future_datetime(hour="18:00:00")
resource_id = booking.find_available_resource(start, end)
if resource_id:
booking.reserve(resource_id, start, end)
else:
print("⚠️ No available slots found.")
if __name__ == "__main__":
main()