-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upload whitelist from LumiNUS export excel
- Loading branch information
Showing
10 changed files
with
204 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# aiVLE CLI | ||
|
||
Course administration utility for [aiVLE](https://github.com/edu-ai/aivle-web) (AI Virtual Learning Environment). | ||
|
||
## Getting started | ||
|
||
Before running the executable, you need to create a `.env` file in the same directory with the following content: | ||
``` | ||
API_ROOT=http://192.168.3.51:8000 | ||
``` | ||
|
||
1. `API_ROOT`: root of aiVLE backend API, for example, `http://127.0.0.1:8000` or `https://aivle-api.leotan.cn/api/v1` | ||
|
||
## Features | ||
|
||
1. Download submissions | ||
2. Download evaluation results as CSV file | ||
3. Upload LumiNUS student roster Excel to aiVLE course whitelist | ||
4. Get API token from username and password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package operations | ||
|
||
import ( | ||
"aivle-cli/models" | ||
"fmt" | ||
"github.com/AlecAivazis/survey/v2" | ||
"net/http" | ||
) | ||
|
||
func selectOneTask(client *http.Client, apiRoot string, token string) (selectedTask models.Task, err error) { | ||
tasks, err := getTasks(client, apiRoot, token) | ||
if err != nil { | ||
return | ||
} | ||
var taskNames []string | ||
for _, task := range tasks { | ||
taskNames = append(taskNames, task.Name) | ||
} | ||
var taskIndex = 0 | ||
err = survey.AskOne(&survey.Select{Message: "Please select a task:", Options: taskNames}, &taskIndex) | ||
if err != nil { | ||
panic(err) | ||
} | ||
selectedTask = tasks[taskIndex] | ||
return | ||
} | ||
|
||
func selectOneCourse(client *http.Client, apiRoot string, token string) (selectedCourse models.Course, err error) { | ||
courses, err := getCourses(client, apiRoot, token) | ||
if err != nil { | ||
return | ||
} | ||
var courseNames []string | ||
for _, course := range courses { | ||
courseNames = append(courseNames, fmt.Sprintf("%s - %s Semester %d", course.Code, course.AcademicYear, course.Semester)) | ||
} | ||
var courseIndex = 0 | ||
err = survey.AskOne(&survey.Select{Message: "Please select a course:", Options: courseNames}, &courseIndex) | ||
if err != nil { | ||
panic(err) | ||
} | ||
selectedCourse = courses[courseIndex] | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package operations | ||
|
||
import ( | ||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/xuri/excelize/v2" | ||
"net/http" | ||
) | ||
|
||
func UploadWhitelist(apiRoot string, token string) { | ||
client := &http.Client{} | ||
// read the student list Excel file | ||
var fileName string | ||
err := survey.AskOne(&survey.Input{Message: "LumiNUS student list file location (.xlsx)"}, &fileName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
f, err := excelize.OpenFile(fileName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer func() { | ||
if err := f.Close(); err != nil { | ||
panic(err) | ||
} | ||
}() | ||
rows, err := f.GetRows("Results") | ||
if err != nil { | ||
panic(err) | ||
} | ||
var emailList []string | ||
for i, row := range rows { | ||
if i <= 2 { | ||
continue | ||
} | ||
emailList = append(emailList, row[1]) | ||
} | ||
// select one of the courses | ||
selectedCourse, err := selectOneCourse(client, apiRoot, token) | ||
if err != nil { | ||
panic(err) | ||
} | ||
// upload the whitelist | ||
for _, email := range emailList { | ||
err = addWhitelist(client, apiRoot, token, selectedCourse.Id, email) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters