]> code.communitydata.science - coldcallbot-discord.git/blob - coldcallbot-manual.py
updated cold call script to do a pure shuffle
[coldcallbot-discord.git] / coldcallbot-manual.py
1 #!/usr/bin/env python3
2
3 from coldcall import ColdCall
4 from datetime import datetime
5 from csv import DictReader
6 from random import sample
7 import json
8 import argparse
9
10 parser = argparse.ArgumentParser(description='run the coldcall bot manually to create a coldcall list')
11
12 parser.add_argument('-n', '--num', dest="num_calls", default=100, const=100, type=int, nargs='?',
13                     help="how many students should be called")
14
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)")
17
18 args = parser.parse_args()
19
20 current_time = datetime.today()
21 with open("configuration.json") as config_file:
22     config = json.loads(config_file.read())
23
24 ## create the coldcall object
25 cc = ColdCall(record_attendance=False)
26
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"]])
33
34 full_names = {}
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
42
43 # get pronouns
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)
49
50 missing_today = [x for x in get_missing(current_time)]
51 # print("Missing Today: ", missing_today)  # useful for debug
52
53 preferred_names = cc.get_preferred_names()
54 # print("Preferred names:", preferred_names)  # useful for debug
55
56 students_present = [s for s in registered_students if s not in missing_today]
57 # print("Students present:", students_present)  # useful for debug
58
59 def print_selected(selected_student):
60     if "print_index" in globals():
61         global print_index
62     else:
63         global print_index
64         print_index = 1
65
66     try:
67         preferred_name = preferred_names[selected_student]
68     except KeyError:
69         preferred_name = "[unknown preferred name]"
70
71     if selected_student in preferred_pronouns:
72         pronouns = preferred_pronouns[selected_student]
73     else:
74         pronouns = "[unknown pronouns]"
75
76     print(f"{print_index}. {preferred_name} :: {pronouns} :: {full_names[selected_student]} :: {selected_student}")
77
78     cc.record_coldcall(selected_student)
79     print_index += 1 ## increase the index
80
81 # if we're in suffle mode
82 shuffle = args.shuffle_roster
83
84 print_index = 1
85
86 if shuffle:
87     for selected_student in sample(students_present, len(students_present)):
88         print_selected(selected_student)
89 else:
90     num_calls = args.num_calls
91
92     for i in range(num_calls):
93         selected_student = cc.select_student_from_list(students_present)
94         print_selected(selected_student)

Community Data Science Collective || Want to submit a patch?