Usage
Installation
$ pip install codepost-powertools
Requires Python 3.7.2+.
Root Folder
You should use a dedicated folder for the usage of these tools, since it requires an input config file and outputs files for certain commands and functions. For instance:
$ GRADING_FOLDER=codePostGrading
$ mkdir $GRADING_FOLDER
$ cd $GRADING_FOLDER
# You can now create the config file in this folder
GRADING_FOLDER $ echo "api_key: $CP_API_KEY" > config.yaml
It is also recommended to use a virtual environment:
GRADING_FOLDER $ VENV=env
GRADING_FOLDER $ python -m venv $VENV
GRADING_FOLDER $ source $VENV/bin/activate
(VENV) GRADING_FOLDER $ python -m pip install codepost-powertools
# You can now use the package
(VENV) GRADING_FOLDER $ cptools --help
(VENV) GRADING_FOLDER $ python my_script.py
In the rest of the documentation, it is assumed that your current directory is this folder and that you have access to the package, either through a global installation or through a virtual environment.
Configuration File
By default, the package will look for a configuration file called
config.yaml that contains a field "api_key" for your codePost API key.
See here
for instructions on how to access your codePost API key, as well as more
information on the config YAML file. You must have admin access to all the
courses you wish to access with this package.
Here is what the config.yaml file may look like:
api_key: YOUR_API_KEY_HERE
Note
This package does not use the default codepost-config.yaml file that
the codepost package uses. However, you can pass a custom path to your
config file to log_in_codepost() if you wish.
Google Sheets OAuth Credentials
This package interacts with Google Sheets through the gspread package. You
can enable an OAuth Client to create, access, and edit spreadsheets using your
account.
To enable an OAuth Client, follow these steps:
Go to the Google Developers Console.
Log in with the Google account you want to use with the OAuth Client. All created spreadsheets will be owned by this account in Google Drive, and all edits will be done with this account.
In the top left, click the “Select a project” dropdown. Here, either select a project to use, or create a new one. The name and organization can be anything.
Note
If your account belongs to an organization, such as school accounts, this may not work depending on your workspace settings. If that happens, use a personal Google account with no organization.
Go to the API Library.
In the search bar, search for “Google Drive API”, select it, and enable it.
Go back to the API Library. In the search bar, search for “Google Sheets API”, select it, and enable it.
Go to the OAuth Consent Screen tab.
If prompted, select “External” for the User Type.
On the “App Information” page, enter an app name. Select your email address for the support email. Scroll down to the bottom and enter your email address for the developer contact information. Click “Save and Continue”.
On the “Scopes” page, click “Save and Continue”.
On the “Test Users” page, add your email address as a user. Click “Save and Continue”.
On the summary page, scroll to the bottom and click “Back to Dashboard”.
Go to the Credentials tab.
At the top of the page, select “+ Create credentials” > “OAuth client ID”.
For the application type, select “Desktop app”. Name your credentials. Click “Create”.
At the popup, click “Download JSON”.
Alternatively, on the Credentials page, locate the credentials you just created in the “OAuth 2.0 Client IDs” table. Click the download button at the end of the row.
Rename the file to
client_credentials.jsonand place it in your root folder.
Note
The user interface of the Google Developers Console may be different when you’re reading this. If it is, please submit an issue or pull request on the GitHub repository.
Note
The script will have access to all the Google Spreadsheets accessible by the account you use, including spreadsheets shared with you. While running the script, only spreadsheets that you specify will be accessed, so be sure to use the proper spreadsheets.
Output Files
The following applies to both commands and functions, and they are used interchangeably.
For certain commands, an output file will be created. To keep these outputs organized, they will be saved according to the following:
All output files will be saved in the folder
output/.If the output file pertains to an entire course, it will be saved in the folder
output/<COURSE>/, where<COURSE>is a combination of the course name and period.If the output file pertains to an assignment, it will be saved in the folder
output/<COURSE>/<ASSIGNMENT>, where<ASSIGNMENT>is the assignment name.
Files will be appropriately named according to the command that generated it.
For some commands, a file may be generated for each student, in which case an
appropriately named folder will be created, either under output/<COURSE>/
or output/<COURSE>/<ASSIGNMENT>/, with each file named for each student.
In the documentation of commands and functions, whenever <OUTPUT>/file.csv
appears, it means that a file named file.csv will be saved at the
appropriate output path, according to the above.
Command Line Interface
You can access the command-line interface with the cptools command:
$ cptools --help
Usage: cptools [OPTIONS] COMMAND [ARGS]...
The `codepost_powertools` package on the command line.
Please see Command-Line Interface for more information.
Importing in Scripts
You can import the package in a script:
import codepost_powertools as cptools
# Log in to codePost
cptools.log_in_codepost()
# Call methods
Please see Writing Scripts for more information.