basic parsing of timeslots.

This commit is contained in:
Clinton Roy 2019-10-12 14:47:33 +11:00 committed by Joel Addison
parent effa0a0fb4
commit 2591a943fe

View file

@ -0,0 +1,44 @@
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)