Created
August 25, 2020 15:27
-
-
Save hmm34/28b89070d61daee336760406e2188260 to your computer and use it in GitHub Desktop.
This file contains 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
# Run: python3 attendance-to-roster.py teamsFile rosterFile -d dateHeader | |
# For example, | |
# python3 attendance-to-roster.py cs100/saved-TeamsAttendance.csv cs100/roster.csv -d 08-24 | |
# | |
# Input : teamsFile, an attendance list downloaded from MS Teams. For example, | |
# Full Name User Action Timestamp | |
# Heather Guarnera Joined 8/24/2020, 9:10:25 AM | |
# Joe Schmoe Joined 8/24/2020, 9:10:31 AM | |
# | |
# Input : rosterFile, an existing roster where attendance for the day will be written. For example, | |
# NAME 24-Aug | |
# Michaud, Heather 1 | |
# Smith, John 1 | |
# | |
# Input: dateHeader, specified attendance date | |
# | |
# Output: Write to an existing roster the attendance for the day. 0 is not present, 1 is present. | |
# - It will indicate any names from attendance list which do not match roster, e.g., | |
# "Heather Guarnera" in Teams does not match "Guarnera, Heather M." in the roster, but it will | |
# match "Guarnera, Heather" in the roster. | |
# - I use this output to fix my roster once so that middle initials are removed, then it matches Teams | |
import argparse, sys | |
import csv | |
parser = argparse.ArgumentParser() | |
parser.add_argument('infile', nargs='?', type=str, default=sys.stdin) | |
parser.add_argument('outfile', nargs='?', type=str, default=sys.stdout) | |
parser.add_argument('--date', '-d', type=str, action='store') | |
args = parser.parse_args() | |
students = {} | |
date = str(args.date) | |
with open(args.infile, encoding='utf-16') as teamsAttendanceFile: | |
line = teamsAttendanceFile.readline() | |
while line: | |
name, action, timestamp = line.split("\t") | |
if action == 'Joined': | |
students[name] = True | |
line = teamsAttendanceFile.readline() | |
all = [] | |
with open(args.outfile, 'r') as inFile: | |
reader = csv.reader(inFile) | |
header = next(reader) | |
header.append(date) | |
all.append(header) | |
for row in reader: | |
studentName = row[0].lstrip().rstrip() # from roster | |
last, first = studentName.split(',') | |
revisedName = (first.lstrip() + " " + last).lstrip().rstrip() | |
if students.get(revisedName): | |
row.append(1) | |
students[revisedName] = False | |
else: | |
row.append(0) | |
all.append(row) | |
writer = csv.writer(open(args.outfile, 'w')) | |
writer.writerows(all) | |
print("Number of attendees:", len(students)) | |
print("Incorrect / invalid names for the following attendees whose names did not match the roster:") | |
for studentName in students.keys(): | |
if students[studentName]: | |
print(studentName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment