-
-
Save nop33/57c682ef08e2bb0e6d28f26c66e0af6d to your computer and use it in GitHub Desktop.
CSV list of booking occurrences for a set of rooms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from io import BytesIO | |
import csv | |
import sys | |
from pytz import timezone | |
from indico.modules.rb.models.reservations import RepeatMapping | |
tz = timezone('Europe/Zurich') | |
room_ids = {96, 336, 97, 98} | |
out = BytesIO() | |
occurrences = ReservationOccurrence.find( | |
Reservation.room_id.in_(room_ids), | |
ReservationOccurrence.start_dt >= tz.localize(datetime(2016, 1, 1)), | |
ReservationOccurrence.end_dt < tz.localize(datetime(2018, 1, 1)), | |
ReservationOccurrence.is_valid, | |
_join=ReservationOccurrence.reservation, | |
_eager=ReservationOccurrence.reservation | |
).options(ReservationOccurrence.NO_RESERVATION_USER_STRATEGY).order_by(ReservationOccurrence.start_dt).all() | |
writer = csv.writer(out) | |
writer.writerow(['Room', 'Reason', 'Booked for', 'Frequency', 'Date', 'Start time', 'End time', 'URL']) | |
for occur in occurrences: | |
reservation = occur.reservation | |
data = [reservation.room.full_name.encode('utf-8'), reservation.booking_reason.encode('utf-8'), | |
reservation.booked_for_name.encode('utf-8'), | |
RepeatMapping.get_short_name(reservation.repeat_frequency, reservation.repeat_interval), | |
occur.start_dt.date(), occur.start_dt.time(), occur.end_dt.time(), reservation.details_url] | |
writer.writerow(data) | |
out.seek(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment