import warnings warnings.simplefilter('default', DeprecationWarning) from fpdf import FPDF import pandas as pd import streamlit as st from datetime import datetime def generate_pdf(df): num_students = df.shape[0] page_body_list = [] for i in range(num_students): if(df.at[i, 'Exam Status'] == "Approved"): # only generates for students who are approved, not for those who are "processing" or "cancelled" # get the data studentName = df.at[i, 'Student'] course = df.at[i, 'Course'] date = df.at[i, 'Date'] loc = df.at[i, 'Exam_Location'] scheduled_start_time = df.at[i, 'Time_Start'] scheduled_end_time = df.at[i, 'Time_End'] # format data with labels studentName = " ".join(["Student's Name:", studentName]) course = " ".join(["Course:", course]) date = " ".join(["Date:", date]) if loc == loc: loc = " ".join(["Location:", loc]) else: loc = "Location: __________________" scheduled_start_time = " ".join(["Scheduled Start Time:", scheduled_start_time]) scheduled_end_time = " ".join(["Scheduled End Time:", scheduled_end_time]) # put grouped info together student_info = "\n".join([studentName, course, date, loc]) scheduled_time = "\n".join([scheduled_start_time, scheduled_end_time]) student_info_and_scheduled_time = "\n".join([student_info, scheduled_time]) notes = "Additional Information:\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________" actual_time = "\n\n\n".join(["Actual Start Time: _____________________________________________________", "Estimated/Adjusted End Time: ___________________________________________", "Actual End Time: ______________________________________________________"]) proctor = "\n\nProctor's Signature: _______________________ Date: _______________________" # construct the body of the pdf body = "\n\n\n".join([student_info_and_scheduled_time, notes, actual_time, proctor]) # add this student's info to the list page_body_list.append(body) pdf = FPDF() for i in range(len(page_body_list)): pdf.add_page() pdf.image("VandyStudentAccessLogo.png", 40, 10, w=120) pdf.set_font('helvetica', 'B', size=16) pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) pdf.set_font('helvetica', 'B', size=16) pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) pdf.set_font('helvetica', 'B', size=8) pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) pdf.set_font('helvetica', 'B', size=14) pdf.cell(w=210, h=9, text="Exam Check-in Form", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) pdf.set_font('helvetica', 'B', size=10) pdf.multi_cell(w=0, h=7, text="This form is to be completed by the proctor. The student must return this \nform along with their seat ticket and all exam materials.\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) pdf.set_font('helvetica', 'B', size=10) pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) pdf.set_font('helvetica', size=13) pdf.multi_cell(0, 7, page_body_list[i]) pdf.set_font('helvetica', 'B', size=10) pdf.set_xy(145, 270) pdf.cell(w=0, h=5, text="# of Exam Pages: _____") pdf.output("/tmp/GraySheets.pdf") return "/tmp/GraySheets.pdf" def main(): st.title("Gray Sheet Generator") # File upload uploaded_file = st.file_uploader("Choose a CSV file", type="csv") if uploaded_file is not None: # Process the file df = pd.read_csv(uploaded_file) pdf_path = generate_pdf(df) todays_date = datetime.now().strftime("%m_%d_%Y") filename = f"GraySheets_{todays_date}.pdf" # Download button with open(pdf_path, "rb") as file: btn = st.download_button( label="Download Gray Sheet", data=file, file_name=filename, mime="application/octet-stream" ) if __name__ == "__main__": main()