Last active
May 3, 2019 07:45
-
-
Save timothycarambat/bf33720952e61782dfa90dd819864ffc to your computer and use it in GitHub Desktop.
Simple Script for Madi that assembles MCA nametags that are needed from a HUGE SLOW online system that takes forever to transcribe from the system to an email.
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
import os, csv, re | |
PATH = "SOME/ABS/PATH" | |
#remove old output files | |
def cleanup(): | |
for file_name in os.listdir(PATH): | |
if '.txt' in file_name: | |
os.remove(file_name) | |
def get_grade(grade_string): | |
return re.findall('\d+', grade_string)[0] | |
def get_tag_count(tag_count_string): | |
return tag_count_string.split(')')[0].split('(')[1] | |
def get_student_lists(): | |
# Review Status, Submitted, xth_Grader's_Name, Homeroom, Number_of_labels, | |
# Number_of_Name_ (price), Are_you_a_member of SC, Student_Council (label), First, Last, Payment Status | |
csv_files = [] | |
student_list = {} | |
for file_name in os.listdir(PATH): | |
if '.csv' in file_name: | |
csv_files.append(file_name) | |
for file in csv_files: | |
print("Reading File: %s" % file) | |
with open(PATH + file) as csv_file: | |
csv_reader = csv.reader(csv_file, delimiter=',') | |
line_count = 0 | |
for data_row in csv_reader: | |
if line_count > 0 and data_row: | |
if data_row[0] == 'Unreviewed' and data_row[10] == 'Completed': | |
grade = get_grade(data_row[3]) | |
tag_count = get_tag_count(data_row[4]) | |
sc_title = data_row[7] if len(data_row[6]) > 0 else None | |
homeroom = data_row[3] | |
student_data = [data_row[2], tag_count, sc_title, homeroom] | |
if "%sth Grade" % grade not in student_list.keys(): | |
student_list["%sth Grade" % grade] = [] | |
student_list["%sth Grade" % grade].append(student_data) | |
line_count += 1 | |
return student_list | |
def make_file_to_be_mailed(student_list, grade_order): | |
text_data = "" | |
for grade in grade_order: | |
if grade not in student_list.keys(): | |
continue | |
students_in_grade = student_list[grade] | |
# write header | |
text_data += "%s: \n" % grade | |
for student_data in students_in_grade: | |
text_data += "%s (%s)" %(student_data[0], student_data[1]) + (" - %s\n" % student_data[2] if student_data[2] else '\n') | |
text_data += "\n\n" | |
file = open( PATH + 'student_data.txt', 'w') | |
file.write(text_data) | |
file.close() | |
def make_file_for_reference(student_list, grade_order): | |
text_data = "~~ DONT FORGET TO MARK ALL THE TAGS AS REVIEWED IN SYSTEM ~~\n\n" | |
for grade in grade_order: | |
if grade not in student_list.keys(): | |
continue | |
students_in_grade = student_list[grade] | |
# write header | |
text_data += "%s: \n" % grade | |
for student_data in students_in_grade: | |
text_data += "%s (%s)" %(student_data[0], student_data[1]) + (" - %s" % student_data[2] if student_data[2] else '') + "; Homeroom: %s\n" % student_data[3] | |
text_data += "\n\n" | |
file = open(PATH + 'student_data_with_homerooms.txt', 'w') | |
file.write(text_data) | |
file.close() | |
ordered_grades = ['8th Grade', '9th Grade', '10th Grade', '11th Grade', '12th Grade'] | |
cleanup() | |
student_list = get_student_lists() | |
make_file_to_be_mailed(student_list, ordered_grades) | |
make_file_for_reference(student_list, ordered_grades) | |
for file_name in os.listdir(PATH): | |
if '.csv' in file_name: | |
os.rename(PATH + file_name, PATH + file_name.split('.')[0] + "_old.csv") |
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
#!/bin/bash | |
/usr/bin/python /Users/<user>/Desktop/Nametag_Solver/nametag_solver.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment