INNER CODE UNIT · Python
synchronize_chatrooms
zapek/Xeres · scripts/bot/bot.py:112
def synchronize_chatrooms(rooms):
print("Syncing chatrooms...")
remaining_rooms = rooms.copy()
while len(remaining_rooms) > 0:
for name in remaining_rooms:
context = get_chat_rooms()
id = find_chat_room(name, context['chatRooms']['subscribed'])
if id != 0:
remaining_rooms.remove(name)
break
id = find_chat_room(name, context['chatRooms']['available'])
if id != 0:
print(f"Subscribing to room {name} with id {id}", name, id)
r = requests.put(XERES_API_URL + XERES_API_PREFIX + "/chat/rooms/" + str(id) + "/subscription")
if r.status_code != 200:
raise RuntimeError(f"Couldn't subscribe to chatroom: {r.status_code}")
remaining_rooms.remove(name)