"""

Generates .pdf files for recruits from an .xlsx spreadsheet made with
`schedule_generator.py`

v1.0 - Peter Winter
v2.0 - Patrick Fuller, [email protected], 22 Oct 12

"""
import os
import subprocess
import re

import file_io

recruits = file_io.read_schedule_xlsx("../generated_schedule.xlsx")

# Specify and create a folder for the .tex files
tex_directory = "../output_latex"
if not os.path.exists(tex_directory):
    os.makedirs(tex_directory)
os.chdir(tex_directory)

# Add .tex files to the folder and subprocess a .pdf converter
for i, recruit in enumerate(recruits):
    filepath = "%s.tex" % re.sub(" ", "_", recruit["name"].lower())
    file_io.write_tex_file(recruit, filepath)
    subprocess.call(["pdflatex", "-interaction=batchmode", filepath])

# Clean up the latex-to-pdf mess
pdf_directory = "../output_pdf"
#!/usr/bin/env python
"""

If a user manually edits the recruit schedule outputted by
`schedule_generator.py`, this will update the corresponding sheets.

"""
import os

import file_io

schedule_file = "../generated_schedule.xlsx"
recruits = file_io.read_schedule_xlsx(schedule_file)
os.remove(schedule_file)
recruit_prefs = file_io.get_recruit_preferences()
professors = file_io.get_professor_availability()

# Merge data structures here for cell coloring
for recruit in recruits:
    for preference in recruit_prefs:
        if preference["name"] == recruit["name"]:
            recruit["preferences"] = preference["preferences"]

# Initialize necessary data stores to allow index access
for professor in professors:
    professor["slots"] = [""] * len(recruits[0]["slots"])
for recruit in recruits:
    recruit["clusters"] = [None] * len(recruit["slots"])

# Map recruit schedule to a professor schedule
for recruit in recruits: