]> code.communitydata.science - coldcallbot-discord.git/commitdiff
read student information using DictReader
authorBenjamin Mako Hill <mako@atdot.cc>
Thu, 8 Oct 2020 15:09:21 +0000 (08:09 -0700)
committerBenjamin Mako Hill <mako@atdot.cc>
Thu, 8 Oct 2020 15:09:21 +0000 (08:09 -0700)
This should be safer.

coldcall.py

index 8cae6ca71e3fcc8791683ecce11e9b6497c8a5d4..2b5b5d88c6b6b8a45e6c3abb3699c00c60a5fbf2 100644 (file)
@@ -38,12 +38,8 @@ class ColdCall():
 
         preferred_names = {}
         with open(self.__fn_studentinfo, 'r') as f:
 
         preferred_names = {}
         with open(self.__fn_studentinfo, 'r') as f:
-            for line in f.readlines():
-                x = line.strip().split("\t")
-                if x[0] == "Timestamp":
-                    continue
-
-                preferred_names[x[4]] = x[2]
+            for row in DictReader(f, delimiter="\t"):
+                preferred_names[row["Your username on the class Discord server"]] = row["Name you'd like to go by in class"]
 
         if selected_student in preferred_names:
             return preferred_names[selected_student]
 
         if selected_student in preferred_names:
             return preferred_names[selected_student]
@@ -103,12 +99,12 @@ class ColdCall():
         return coldcall_message
 
 # cc = ColdCall()
         return coldcall_message
 
 # cc = ColdCall()
+# test_student_list = ["jordan", "Kristen Larrick", "Madison Heisterman", "Maria.Au20", "Laura (Alia) Levi", "Leona Aklipi", "Linya Feng", "anne", "kirst", "emmaaitelli", "ashleylee", "allie_partridge", "Tiana_Cole", "Hamin", "Ella Qu", "Angel Su", "Shizuka", "Ben Baird", "Kim Do", "Isaacm24", "Sam Bell", "Courtneylg", "TasnimHasan"]
+# print(cc.coldcall(test_student_list))
 
 
-# test_student_list = ["Jordan", "Kristen Larrick", "Madison Heisterman", "Maria.Au20", "Laura (Alia) Levi", "Leona Aklipi", "Linya Feng", "anne", "kirst", "emmaaitelli", "ashleylee", "allie_partridge", "Tiana_Cole", "Hamin", "Ella Qu", "Angel Su", "Shizuka", "Ben Baird", "Kim Do", "Isaacm24", "Sam Bell", "Courtneylg", "TasnimHasan"]
-# cc.coldcall(test_student_list)
-
-# test_student_list = ["Jordan", "Kristen Larrick", "Mako"]
-# cc.coldcall(test_student_list)
+# test_student_list = ["jordan", "Kristen Larrick", "Mako"]
+# print(cc.coldcall(test_student_list))
 
 
-# test_student_list = ["Jordan", "Kristen Larrick"]
-# cc.coldcall(test_student_list)
+# test_student_list = ["jordan", "Kristen Larrick"]
+# print(cc.coldcall(test_student_list))

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