symposion_app/pinaxcon/registrasion/management/commands/update_schedule.py
2019-10-19 11:38:29 +10:00

44 lines
1.4 KiB
Python

from django.core.management.base import BaseCommand
from collections import Counter
from pathlib import Path
import csv
class Command(BaseCommand):
known_headers = ["date", "start time", "end time", "kind", "rooms"]
help = "Updates the schedule based on two csv files, "\
"one that gives all the talk slots, the other the talks."
def find_or_create_slot(self, date, start_time, end_time, room):
print(date, start_time, end_time, room)
return (date, start_time, end_time, room)
def add_arguments(self, parser):
parser.add_argument('timeslots', type=Path)
parser.add_argument('talks', nargs="?", type=Path, default=None)
def handle(self, *args, **options):
slot = {}
slot_type_count = Counter()
with open(options['timeslots']) as csv_file:
csv_reader = csv.reader(csv_file)
headers = next(csv_reader)
assert headers == self.known_headers
for row in csv_reader:
assert len(row) == len(self.known_headers)
date, start_time, end_time, kind, rooms = row
slot_type_count[(date, kind)] += 1
for room in rooms.split(';'):
room = room.strip()
slot[(date, kind, slot_type_count[(date, kind)])] = self.find_or_create_slot(
date, start_time, end_time, room)