new
This commit is contained in:
parent
4f4046e4a0
commit
716a565713
6 changed files with 1471 additions and 15 deletions
|
|
@ -71,6 +71,7 @@ class BookingClient:
|
||||||
"customer_note": "",
|
"customer_note": "",
|
||||||
"add_ons_by_service": {SERVICE_ID: [[]]},
|
"add_ons_by_service": {SERVICE_ID: [[]]},
|
||||||
"sub_bookings_by_service": {},
|
"sub_bookings_by_service": {},
|
||||||
|
# INFO: changes every week: e.g. booking for a monday needs new id
|
||||||
# "booking_quota_grant_id":"24735199",
|
# "booking_quota_grant_id":"24735199",
|
||||||
"booking_quota_grant_id": "24735202",
|
"booking_quota_grant_id": "24735202",
|
||||||
"strategy": "multi-resource",
|
"strategy": "multi-resource",
|
||||||
|
|
@ -86,7 +87,9 @@ class BookingClient:
|
||||||
try:
|
try:
|
||||||
data = booking.json().get("data", {})
|
data = booking.json().get("data", {})
|
||||||
except (ValueError, JSONDecodeError):
|
except (ValueError, JSONDecodeError):
|
||||||
# print(f"❌ Invalid JSON response from booking request: {booking.text[:200]}")
|
if "Bad Request" in booking.text and "400" in booking.text:
|
||||||
|
print("❌ Bad Request 400 on Booking request.")
|
||||||
|
else:
|
||||||
print(f"❌ Invalid JSON response from booking request: {booking.text}")
|
print(f"❌ Invalid JSON response from booking request: {booking.text}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,10 @@ SERVICE_ID = "601"
|
||||||
# RESOURCE_ID =15994 # 91 height adjustable desk
|
# RESOURCE_ID =15994 # 91 height adjustable desk
|
||||||
# RESOURCE_ID =16402 # 222 study room
|
# RESOURCE_ID =16402 # 222 study room
|
||||||
# RESOURCE_ID =15883 #66 second best
|
# RESOURCE_ID =15883 #66 second best
|
||||||
RESOURCE_ID = 15502 # 17 cool snipe with view
|
# RESOURCE_ID = 15502 # 17 cool snipe with view
|
||||||
RESOURCE_IDS = []
|
# RESOURCE_IDS = [15502, 15883, 16402]
|
||||||
# RESOURCE_IDS = [15502, 15883]
|
# RESOURCE_ID = None
|
||||||
|
RESOURCE_IDS = [15883, 15502, 15880, 15505, 15892]
|
||||||
|
|
||||||
TIMEZONE = "Europe/Berlin"
|
TIMEZONE = "Europe/Berlin"
|
||||||
# SSO_PROVIDER = "kit" # Available: kit (add more in auth/providers/)
|
# SSO_PROVIDER = "kit" # Available: kit (add more in auth/providers/)
|
||||||
|
|
|
||||||
4
development_process.md
Normal file
4
development_process.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
|
1. add support for changing week ID automatically
|
||||||
|
2. only use resource_ids list and remove others
|
||||||
14
main.py
14
main.py
|
|
@ -7,7 +7,7 @@ from auth.session import AnnySession
|
||||||
from booking.client import BookingClient
|
from booking.client import BookingClient
|
||||||
from utils.helpers import get_future_datetime
|
from utils.helpers import get_future_datetime
|
||||||
import pytz
|
import pytz
|
||||||
from config.constants import RESOURCE_ID, TIMEZONE, SSO_PROVIDER, BOOKING_TIMES, RESOURCE_IDS
|
from config.constants import TIMEZONE, SSO_PROVIDER, BOOKING_TIMES, RESOURCE_IDS
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
@ -38,7 +38,7 @@ def main():
|
||||||
max_wait_seconds = 10 * 60 # 10 minutes
|
max_wait_seconds = 10 * 60 # 10 minutes
|
||||||
|
|
||||||
if 0 < seconds_until_midnight <= max_wait_seconds:
|
if 0 < seconds_until_midnight <= max_wait_seconds:
|
||||||
print("⏳ Waiting {seconds_until_midnight:.0f} seconds until midnight...")
|
print(f"⏳ Waiting {seconds_until_midnight:.0f} seconds until midnight...")
|
||||||
time.sleep(seconds_until_midnight)
|
time.sleep(seconds_until_midnight)
|
||||||
elif seconds_until_midnight > max_wait_seconds:
|
elif seconds_until_midnight > max_wait_seconds:
|
||||||
print("⚡ More than 10 min until midnight, executing immediately...")
|
print("⚡ More than 10 min until midnight, executing immediately...")
|
||||||
|
|
@ -56,11 +56,11 @@ def main():
|
||||||
if reservation_success:
|
if reservation_success:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if RESOURCE_ID:
|
# if RESOURCE_ID:
|
||||||
resource_id = RESOURCE_ID
|
# resource_id = RESOURCE_ID
|
||||||
reservation_success = booking.reserve(resource_id, start, end)
|
# reservation_success = booking.reserve(resource_id, start, end)
|
||||||
if reservation_success:
|
# if reservation_success:
|
||||||
return True
|
# return True
|
||||||
resource_id = booking.find_available_resource(start, end)
|
resource_id = booking.find_available_resource(start, end)
|
||||||
reservation_success = booking.reserve(resource_id, start, end)
|
reservation_success = booking.reserve(resource_id, start, end)
|
||||||
if reservation_success:
|
if reservation_success:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,24 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
with open("nice.json", "r", encoding="utf-8") as f:
|
with open("data.json", "r", encoding="utf-8") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
|
keys_to_keep = {"name"}
|
||||||
|
keys_to_keep2 = {"attributes", "id"}
|
||||||
for i in data["data"]:
|
for i in data["data"]:
|
||||||
print("%-32s id: %s" % (i["attributes"]["name"], i["id"]))
|
attr = i["attributes"]
|
||||||
print(type(data)) # usually <class 'dict'>
|
for key in list(attr.keys()):
|
||||||
|
if key not in keys_to_keep:
|
||||||
|
del attr[key]
|
||||||
|
for key in list(i.keys()):
|
||||||
|
if key not in keys_to_keep2:
|
||||||
|
del i[key]
|
||||||
|
# i["attributes"].pop("description", None) # safe remove
|
||||||
|
# i["attributes"].pop("plain_description", None) # safe remove
|
||||||
|
|
||||||
|
with open("data.json", "w") as f:
|
||||||
|
json.dump(data, f, indent=2)
|
||||||
|
|
||||||
|
# for i in data["data"]:
|
||||||
|
# print("%-32s id: %s" % (i["attributes"]["name"], i["id"]))
|
||||||
|
# print(type(data)) # usually <class 'dict'>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue