feat(canvas): export all users
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				build / trigger-build-image (push) Successful in 13s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	build / trigger-build-image (push) Successful in 13s
				
			This commit is contained in:
		
							parent
							
								
									beeb45709f
								
							
						
					
					
						commit
						353797323d
					
				|  | @ -34,9 +34,9 @@ class Tea: | ||||||
| tea = Tea()  # lazy loader | tea = Tea()  # lazy loader | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @app.command("export-students", help="export students from canvas to csv file") | @app.command("export-users", help="export users from canvas to csv file") | ||||||
| def export_students_to_csv(output_file: Path) -> None: | def export_users_to_csv(output_file: Path = Argument("students.csv")) -> None: | ||||||
|     tea.pot.canvas.export_students_to_csv(output_file) |     tea.pot.canvas.export_users_to_csv(output_file) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @app.command( | @app.command( | ||||||
|  |  | ||||||
|  | @ -35,7 +35,7 @@ class Canvas: | ||||||
|         # types = ["student", "observer"] |         # types = ["student", "observer"] | ||||||
|         types = ["student"] |         types = ["student"] | ||||||
| 
 | 
 | ||||||
|         def patch_student(student: User) -> User: |         def patch_user(student: User) -> User: | ||||||
|             student.name = ( |             student.name = ( | ||||||
|                 re.sub(r"[^\x00-\x7F]+", "", student.name).strip().title() |                 re.sub(r"[^\x00-\x7F]+", "", student.name).strip().title() | ||||||
|             )  # We only care english name |             )  # We only care english name | ||||||
|  | @ -44,7 +44,7 @@ class Canvas: | ||||||
|             return student |             return student | ||||||
| 
 | 
 | ||||||
|         self.students = [ |         self.students = [ | ||||||
|             patch_student(student) |             patch_user(student) | ||||||
|             for student in self.course.get_users(enrollment_type=types) |             for student in self.course.get_users(enrollment_type=types) | ||||||
|         ] |         ] | ||||||
|         for attr in ["login_id", "name"]: |         for attr in ["login_id", "name"]: | ||||||
|  | @ -52,6 +52,7 @@ class Canvas: | ||||||
|                 raise Exception( |                 raise Exception( | ||||||
|                     f"Unable to gather students' {attr}, please contact the Canvas site admin" |                     f"Unable to gather students' {attr}, please contact the Canvas site admin" | ||||||
|                 ) |                 ) | ||||||
|  |         self.users = [patch_user(student) for student in self.course.get_users()] | ||||||
|         logger.debug("Canvas students loaded") |         logger.debug("Canvas students loaded") | ||||||
|         self.assignments = self.course.get_assignments() |         self.assignments = self.course.get_assignments() | ||||||
|         logger.debug("Canvas assignments loaded") |         logger.debug("Canvas assignments loaded") | ||||||
|  | @ -60,12 +61,12 @@ class Canvas: | ||||||
|         self.grade_filename = grade_filename |         self.grade_filename = grade_filename | ||||||
|         logger.debug("Canvas initialized") |         logger.debug("Canvas initialized") | ||||||
| 
 | 
 | ||||||
|     def export_students_to_csv(self, filename: Path) -> None: |     def export_users_to_csv(self, filename: Path) -> None: | ||||||
|         with open(filename, mode="w", newline="") as file: |         with open(filename, mode="w", newline="") as file: | ||||||
|             writer = csv.writer(file) |             writer = csv.writer(file) | ||||||
|             for student in self.students: |             for user in self.users: | ||||||
|                 writer.writerow([student.name, student.sis_id, student.login_id]) |                 writer.writerow([user.name, user.sis_id, user.login_id]) | ||||||
|         logger.info(f"Students exported to {filename}") |         logger.info(f"Users exported to {filename}") | ||||||
| 
 | 
 | ||||||
|     def prepare_assignment_dir( |     def prepare_assignment_dir( | ||||||
|         self, dir_or_zip_file: str, create_grade_file: bool = True |         self, dir_or_zip_file: str, create_grade_file: bool = True | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user