Skip to content

Commit

Permalink
adding canvas token read from file, updating docs and bumpging version
Browse files Browse the repository at this point in the history
  • Loading branch information
dsavransky committed Jul 20, 2020
1 parent 470879e commit fd6a831
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cornellGrading/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name = "cornellGrading"
__version__ = '1.0.1'
__version__ = '1.1.0'
from .cornellGrading import cornellGrading
20 changes: 16 additions & 4 deletions cornellGrading/cornellGrading.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ class cornellGrading:
"""

def __init__(self, canvasurl="https://canvas.cornell.edu"):
def __init__(self, canvasurl="https://canvas.cornell.edu", canvas_token_file=None):
""" Ask for token, store it if you can connect, and
save resulting canvas object
To generate token: in Canvas: Settings>Account>Approved Integrations
Click '+New Access Token'. Copy the token.
Args:
canvasurl (str):
Base URL of Canvas
canvas_token_file (str):
Full path to text file with canvas token on disk.
Notes:
To generate token: in Canvas: Settings>Account>Approved Integrations
Click '+New Access Token'. Copy the token.
.. warning::
The token will *not* be displayed again. However, it will be saved securely
Expand All @@ -54,7 +61,12 @@ def __init__(self, canvasurl="https://canvas.cornell.edu"):

token = keyring.get_password("canvas_test_token1", "canvas")
if token is None:
token = getpass.getpass("Enter canvas token:\n")
if canvas_token_file is None:
token = getpass.getpass("Enter canvas token:\n")
else:
with open("canvas_token.txt", "r") as f:
tmp = f.read()
token = tmp.strip()
try:
canvas = Canvas(canvasurl, token)
canvas.get_current_user()
Expand Down
11 changes: 8 additions & 3 deletions documentation/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ Canvas API Token
===================
To generate token, in Canvas:

#. Navigate to Settings>Account>Approved Integrations
#. Navigate to Account>Settings and scroll down to Approved Integrations
#. Click '+New Access Token'. Copy the token. **NB: It won't be displayed again.**

You will need to enter this token the first time you instantiate a :py:class:`cornellGrading.cornellGrading` object.
You will need to enter this token the first time you instantiate a :py:class:`cornellGrading.cornellGrading` object. If using Windows, you should save this token to a text file. Be sure that there is nothing other than the token in the file (white space afterwards is ok).

.. note::

Expand Down Expand Up @@ -88,7 +88,7 @@ Now, in python:

.. code-block:: python
from cornellGrading import cornellGrading
from cornellGrading import cornellGrading
#connect to canvas
#if this is your first time doing this, you'll be prompted
Expand All @@ -112,6 +112,11 @@ Now, in python:
#generate course mailing list
c.genCourseMailingList()
.. note::

On Windows, when running python in a ``cmd`` shell, pasting the API token into the shell will **not** work. Instead, you can provide your token via a plain-text file, by using the keyword ``canvas_token_file`` and providing the full path to the file containing your token. So, the first `cornellGrading` call above would be: ``c = cornellGrading(canvas_token_file='path_to_token_file')``. Note that you only need to do this on your first ever instantiation of the object - the token will be save to your system's keychain after the first successful connection. You can then delete the text file from your system, if you wish, or save it for future use (but be sure to save it in a secure fashion).



Upload a Homework and Create a New Assignment
-----------------------------------------------
Expand Down

0 comments on commit fd6a831

Please sign in to comment.