feat: csv export (#50)

This commit is contained in:
mQzLjP 2025-02-23 21:31:02 +08:00 committed by GitHub
parent d564aff885
commit 3ab340f688
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -35,6 +35,11 @@ class Tea:
tea = Tea() # lazy loader
@app.command("export-students", help="export students from canvas to csv file")
def export_students_to_csv(output_file: Path) -> None:
tea.pot.canvas.export_students_to_csv(output_file)
@app.command(
"invite-to-teams", help="invite all canvas students to gitea teams by team name"
)

View File

@ -1,6 +1,8 @@
import csv
import os
import re
from glob import glob
from pathlib import Path
from typing import cast
from canvasapi import Canvas as PyCanvas
@ -58,6 +60,13 @@ class Canvas:
self.grade_filename = grade_filename
logger.debug("Canvas initialized")
def export_students_to_csv(self, filename: Path) -> None:
with open(filename, mode="w", newline="") as file:
writer = csv.writer(file)
for student in self.students:
writer.writerow([student.name, student.sis_id, student.login_id])
logger.info(f"Students exported to {filename}")
def prepare_assignment_dir(
self, dir_or_zip_file: str, create_grade_file: bool = True
) -> None: