3 from coldcall import ColdCall
4 from datetime import datetime
5 from csv import DictReader
6 from random import sample
10 parser = argparse.ArgumentParser(description='run the coldcall bot manually to create a coldcall list')
12 parser.add_argument('-n', '--num', dest="num_calls", default=100, const=100, type=int, nargs='?',
13 help="how many students should be called")
15 parser.add_argument('-s', '--shuffle', dest="shuffle_roster", action="store_true",
16 help="select without replacement (i.e., call each person once with n equal to the group size)")
18 args = parser.parse_args()
20 current_time = datetime.today()
21 with open("configuration.json") as config_file:
22 config = json.loads(config_file.read())
24 ## create the coldcall object
25 cc = ColdCall(record_attendance=False)
27 def get_missing(d=current_time):
28 date_string = f'{d.month}/{d.day}/{d.year}'
29 with open(config["optout_file"], 'r') as f:
30 for row in DictReader(f, delimiter="\t"):
31 if row["Date of class session you will be absent"] == date_string:
32 yield(row[config["unique_name_rowname"]])
35 registered_students = []
36 with open(config["roster_file"], 'r') as f:
37 for row in DictReader(f, delimiter=","):
38 student_no = row["StudentNo"].strip()
39 registered_students.append(student_no)
40 full_names[student_no] = f"{row[config['roster_firstname_rowname']]} {row[config['roster_lastname_rowname']]}"
41 # print("Registered:", registered_students) # useful for debug
44 with open(config["student_info_file"], 'r') as f:
45 preferred_pronouns = {}
46 for row in DictReader(f, delimiter="\t"):
47 preferred_pronouns[row[config["unique_name_rowname"]]] = row["Preferred pronouns"]
48 # print(preferred_pronouns)
50 missing_today = [x for x in get_missing(current_time)]
51 # print("Missing Today: ", missing_today) # useful for debug
53 preferred_names = cc.get_preferred_names()
54 # print("Preferred names:", preferred_names) # useful for debug
56 students_present = [s for s in registered_students if s not in missing_today]
57 # print("Students present:", students_present) # useful for debug
59 def print_selected(selected_student):
60 if "print_index" in globals():
67 preferred_name = preferred_names[selected_student]
69 preferred_name = "[unknown preferred name]"
71 if selected_student in preferred_pronouns:
72 pronouns = preferred_pronouns[selected_student]
74 pronouns = "[unknown pronouns]"
76 print(f"{print_index}. {preferred_name} :: {pronouns} :: {full_names[selected_student]} :: {selected_student}")
78 cc.record_coldcall(selected_student)
79 print_index += 1 ## increase the index
81 # if we're in suffle mode
82 shuffle = args.shuffle_roster
87 for selected_student in sample(students_present, len(students_present)):
88 print_selected(selected_student)
90 num_calls = args.num_calls
92 for i in range(num_calls):
93 selected_student = cc.select_student_from_list(students_present)
94 print_selected(selected_student)