diff --git a/.gitignore b/.gitignore index e5ebe735a6c22a5cc1f97fa557eaf1e35750f9cc..fca862cc7f274ae6abab3b563b01f09a54beb36d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Project-specific config.py +abet_oat.json # Mac file finder metadata .DS_Store diff --git a/README-images/selecting-a-course.png b/README-images/selecting-a-course.png index dbc1fdf8df17069f49d29888d86a762ed33305d1..917ac7af5811a306787413a5f9368462f68a1c68 100644 Binary files a/README-images/selecting-a-course.png and b/README-images/selecting-a-course.png differ diff --git a/README.md b/README.md index 1cd78daf7836b6e15aa63ab1e60215c5ef717960..f8310d064bef3ebdc55ef5f16c06bdd5483de73d 100644 --- a/README.md +++ b/README.md @@ -7,45 +7,42 @@ selected courses. ### Dependencies -You need Python. I think Python 3.6 and newer will work fine. +- [x] You need Python. I think Python 3.6 and newer will work fine. -You need the `canvasapi` module. Run -``` -pip install canvasapi -``` -*Note*: I'm pretty sure this is **not** the same module that Chris Bourke -demonstrated a couple of years ago. - +- [x] You need the `canvasapi` module. Run + ``` + pip install canvasapi + ``` ### Getting a Canvas API Key -To interface with Canvas, you need a Canvas API Key. Log into Canvas and click -on the *Account* icon in the left gutter. In the resulting menu, click on -*Settings*. +To interface with Canvas, you need a Canvas API Key. - +- [ ] Log into Canvas and click on the *Account* icon in the left gutter. In + the resulting menu, click on *Settings*. -On your account settings page, scroll down until you see the `+ New Access -Token` button. Click on that button. Fill out the fields in the popup window -and click on `Generate Token`. You will then get a new popup window with the -token's details. ***DO NOT close this window yet***. +  - +- [ ] On your account settings page, scroll down until you see the `+ New + Access Token` button. Click on that button. Fill out the fields in the popup + window and click on `Generate Token`. You will then get a new popup window + with the token's details. ***DO NOT close this window yet***. -Copy the `config-example.py` file to `config.py` and open `config.py` for -editing. Delete the text *Your Canvas API Key goes here* (leave the opening- -and closing-quotes). Copy the token from your browser's popup window and paste -it between the opening- and closing-quotes in `config.py`. +  + +- [ ] Copy the `abet_oat-example.json` file to `~/.abet_oat.json` and open + `~/.abet_oat.json` for editing. Delete the text *Your Canvas API Key goes + here* (leave the opening- and closing-quotes). Copy the token from your + browser's popup window and paste it between the opening- and closing-quotes + in `~/.abet_oat.json`. - +  -### Getting Students' Majors +### You no longer need to... You no longer need to manually retrieve students' majors from MyRed. The program now retrieves students' majors from directory.unl.edu. -### Edit `rosters.csv` - You no longer need to maintain a rosters file. The program now retrieves your courses from Canvas for a specified semester. @@ -53,7 +50,7 @@ courses from Canvas for a specified semester. Start the program with ``` -python analyze_grades.py +~cabohn/abet_oat/analyze_grades.py ``` You will be prompted to confirm the program's best-guess of the semester you want to analyze. Confirm the semester or select a different semester. You will diff --git a/abet_oat-example.json b/abet_oat-example.json new file mode 100644 index 0000000000000000000000000000000000000000..7ad35df45e3382f8fa93f3c5be2d081e4c663453 --- /dev/null +++ b/abet_oat-example.json @@ -0,0 +1,3 @@ +{ + "canvas_api_key": "Your Canvas API Key goes here" +} diff --git a/analyze_grades.py b/analyze_grades.py index 66e48be468df6b865f706dbc461d014c162a38ef..bb9587abb7d58f1bb77f371adec1b4965253a5a2 100644 --- a/analyze_grades.py +++ b/analyze_grades.py @@ -1,9 +1,10 @@ +#!/usr/local/python/.pyenv/shims/python + import datetime import statistics import sys from typing import List, Optional, Dict, Set -import common_functions from api.canvas_classes import CanvasAssignment, CanvasAssignmentGroup, CanvasCourse, CanvasUser from common_functions import select_from_list from majors import Major diff --git a/api/canvas_classes.py b/api/canvas_classes.py index 04f698eca91f42d5eb85fdc71f754b765cedb402..83deb5b877d278836a11b62352ac2a97773940f1 100644 --- a/api/canvas_classes.py +++ b/api/canvas_classes.py @@ -1,4 +1,6 @@ +import json from datetime import datetime +from pathlib import Path from typing import ClassVar, Dict, Iterable, List, Optional, Union from canvasapi import Canvas @@ -11,16 +13,22 @@ from canvasapi.section import Section from canvasapi.submission import Submission from canvasapi.user import User -from config import Config - class CanvasSession: __instance: ClassVar[Canvas] = None @classmethod def get_session(cls) -> Canvas: + api_key_file = f'{Path.home()}/.abet_oat.json' + canvas_url = 'https://canvas.unl.edu/' if cls.__instance is None: - cls.__instance = Canvas(Config.canvas_url, Config.canvas_api_key) + canvas_api_key: str = '' + try: + with open(api_key_file, mode='r') as json_file: + canvas_api_key = json.load(json_file)['canvas_api_key'] + except FileNotFoundError: + canvas_api_key = input(f'{api_key_file} not found. Please enter your Canvas API key: ') + cls.__instance = Canvas(canvas_url, canvas_api_key) return cls.__instance diff --git a/config-example.py b/config-example.py deleted file mode 100644 index d1e2a55b092cbdc1b4a891d847a0b0ffb282c6c4..0000000000000000000000000000000000000000 --- a/config-example.py +++ /dev/null @@ -1,4 +0,0 @@ -class Config: - # Canvas API configuration - canvas_url = 'https://canvas.unl.edu/' - canvas_api_key = 'Your Canvas API Key goes here'