From c66288b826fe9bd2647fcca89055fbc17bf418f0 Mon Sep 17 00:00:00 2001 From: Whodiduexpect <53096512+Whodiduexpect@users.noreply.github.com> Date: Sat, 29 Feb 2020 17:34:47 -0800 Subject: [PATCH 1/9] Added the ability to list added assignments, optimized listing completed, and fixed an issue where it would prevent you from exiting. --- assignment_list.py | 417 ++++++++++++++++++---------------- studentvue_parser.py | 28 ++- tests/list_added_none_test.py | 32 +++ 3 files changed, 266 insertions(+), 211 deletions(-) create mode 100644 tests/list_added_none_test.py diff --git a/assignment_list.py b/assignment_list.py index 88f6bde..6df44bd 100644 --- a/assignment_list.py +++ b/assignment_list.py @@ -1,200 +1,217 @@ -#!/usr/bin/env python3 -import os -import random -import sys -from pathlib import Path - -import click -import pandas as pd - -import studentvue_parser - - -# Define functions -def open_data(file, mode): - return open(Path('data/%s' % file), mode) - - -def list_assignments(assignments): - assignments_view = assignments[assignments['is_completed'] != True] - assignments_view = assignments_view.drop(columns=['is_completed']) - if assignments_view.empty: - click.echo('No assignments to do!') - else: - click.echo(assignments_view) - - -def list_completed(assignments): - assignments_view = assignments[assignments['is_completed']] - assignments_view = assignments_view.drop(columns=['is_completed']) - if assignments_view.empty: - click.echo('No assignments completed yet.') - else: - click.echo(assignments_view) - - -def get_data_from_file(filename, split_char): - file = open_data(filename, 'r') - output = file.read().split(split_char) - file.close() - return output - - -def update_csv(assignments): - assignments.to_csv( - Path('data/studentvue_assignments.csv'), - sep='/', - index=False) - - -def create_if_not_exist(filename): - if not os.path.exists(Path('data/%s' % filename)): - file = open_data(filename, 'w') - file.close() - - -# Main -def main(): - # If the credential file does not exist: - if not os.path.exists(Path('data/studentvue_credentials')): - # If we don't even have a data folder: - if not os.path.exists('data'): - # Create one - os.mkdir('data') - # Now that we know we have a data folder, let's set the credentials - studentvue_parser.set_credentials() - - # Read the credential file - credentials = get_data_from_file('studentvue_credentials', ',') - - # Define commands - @click.group() - def cli(): - """ - A Student Vue assignment manager - """ - - @cli.command() - def reset(): - """ - Reset credentials - """ - studentvue_parser.set_credentials() - - @cli.command() - @click.argument('category', required=False) - def list(category): - """ - List assignments by CATEGORY (defaults to 'current') - """ - if not category: - category = 'current' - if category == 'current': - assignments = studentvue_parser.get_assignments(credentials) - list_assignments(assignments) - elif category == 'completed': - assignments = studentvue_parser.get_assignments(credentials) - list_completed(assignments) - else: - click.echo( - '"%s" is not a valid category. The categories are "current" and "completed"' % - category) - - @cli.command() - @click.argument('id') - def complete(id): - """ - Complete an assignment by assignment ID - """ - assignments = studentvue_parser.get_assignments(credentials) - try: - assignments.at[assignments.loc[assignments['Assignment ID'].isin( - [id])].index, 'is_completed'] = True - update_csv(assignments) - except BaseException: - click.echo('Failed to complete assignment #%s' % id) - sys.exit() - click.echo('Marked assignment #%s as complete' % id) - - @cli.command() - @click.argument('id') - def incomplete(id): - """ - Mark an assignment as incomplete by assignment ID - """ - assignments = studentvue_parser.get_assignments(credentials) - try: - assignments.at[assignments.loc[assignments['Assignment ID'].isin( - [id])].index, 'is_completed'] = False - update_csv(assignments) - except BaseException: - click.echo('Failed to mark assignment #%s as incomplete' % id) - sys.exit() - click.echo('Marked assignment #%s as incomplete' % id) - - @cli.command() - @click.argument('title') - @click.argument('date') - def add(title, date): - """ - Add a new assignment with the TITLE and DATE - """ - - # Get schedule - classes = studentvue_parser.get_schedule(credentials) - valid = False - while not valid: - # Print all the classes - for class_ in classes: - print(class_) - - # Ask which period to add the assignment to - class_period_input = input( - '\nWhich class period do you want to add the assignment "%s" to? ' % - title) - try: # Check if the input can even be converted to an integer! - class_period = int(class_period_input) - except ValueError: - click.echo('"%s" is an invalid input' % class_period) - # Check that if the input is an integer, that it is a valid period - if class_period > len(classes) or class_period < 1: - click.echo("Invalid period.\n") - else: - valid = True - - # Auto generate the class name as if it was from Student Vue - teacher_fullname = classes[class_period - 1].teacher.name.split(' ') - teacher_label = '{0}, {1}'.format( - teacher_fullname[1], teacher_fullname[0][:1]) - class_name = '{0} {1}({2})'.format(teacher_label, - classes[class_period - 1].name, - classes[class_period - 1].period) - - # Generate a assignment list 8 digit id, and make sure it's unique - assignments = studentvue_parser.get_assignments(credentials) - id_unique = False - - while not id_unique: - generated_id = random.randrange(11111111, 99999999, 1) - is_id_unique = True - for assignment_id in assignments["Assignment ID"]: - if assignment_id == generated_id: - is_id_unique = False - if is_id_unique: - id_unique = True - - # Make the assignment based on data we have collected/generated - assignment_df = pd.DataFrame({'Assignment ID': [generated_id], 'Class Name': [ - class_name], 'Due Date': [date], 'Assignment': [title], 'is_completed': ['False']}) - assignments = assignments.append(assignment_df, sort=True) - convert_dict = {'Assignment ID': int} - assignments = assignments.astype(convert_dict) - update_csv(assignments) - click.echo('Successfully added assignment "{0}"'.format(title)) - - # Execute command - cli(obj={}) - - -if __name__ == '__main__': - main() +#!/usr/bin/env python3 +import os +import random +import sys +from pathlib import Path + +import click +import pandas as pd + +import studentvue_parser + + +# Define functions +def open_data(file, mode): + return open(Path('data/%s' % file), mode) + + +def list_assignments(assignments): + assignments_view = assignments[assignments['is_completed'] != True] + assignments_view = assignments_view.drop(columns=['is_completed']) + if assignments_view.empty: + click.echo('No assignments to do!') + else: + click.echo(assignments_view) + + +def list_completed(assignments): + assignments_view = assignments[assignments['is_completed']] + assignments_view = assignments_view.drop(columns=['is_completed']) + if assignments_view.empty: + click.echo('No assignments completed yet.') + else: + click.echo(assignments_view) + +def list_added(assignments): + assignments_view = assignments.drop(columns=['is_completed']) + assignments_view['Assignment ID'] = assignments['Assignment ID'].astype('str') + mask = (assignments_view['Assignment ID'].str.len() == 8) + assignments_view = assignments_view.loc[mask] + if assignments_view.empty: + click.echo('No assignments added yet.') + else: + click.echo(assignments_view) + + +def get_data_from_file(filename, split_char): + file = open_data(filename, 'r') + output = file.read().split(split_char) + file.close() + return output + + +def update_csv(assignments): + assignments.to_csv( + Path('data/studentvue_assignments.csv'), + sep='/', + index=False) + + +def create_if_not_exist(filename): + if not os.path.exists(Path('data/%s' % filename)): + file = open_data(filename, 'w') + file.close() + + +# Main +def main(): + # If the credential file does not exist: + if not os.path.exists(Path('data/studentvue_credentials')): + # If we don't even have a data folder: + if not os.path.exists('data'): + # Create one + os.mkdir('data') + # Now that we know we have a data folder, let's set the credentials + studentvue_parser.set_credentials() + + # Read the credential file + + # Define commands + @click.group() + def cli(): + """ + A Student Vue assignment manager + """ + + @cli.command() + def reset(): + """ + Reset credentials + """ + studentvue_parser.set_credentials() + + @cli.command() + @click.argument('category', required=False) + def list(category): + """ + List assignments by CATEGORY (defaults to 'current') + """ + if not category: + category = 'current' + if category == 'current': + credentials = get_data_from_file('studentvue_credentials', ',') + assignments = studentvue_parser.get_assignments(credentials) + list_assignments(assignments) + elif category == 'completed': + assignments = studentvue_parser.get_stored_assignment_data() + list_completed(assignments) + elif category == 'added': + assignments = studentvue_parser.get_stored_assignment_data() + list_added(assignments) + else: + click.echo( + '"%s" is not a valid category. The categories are "current" and "completed"' % + category) + + @cli.command() + @click.argument('id') + def complete(id): + """ + Complete an assignment by assignment ID + """ + credentials = get_data_from_file('studentvue_credentials', ',') + assignments = studentvue_parser.get_assignments(credentials) + try: + assignments.at[assignments.loc[assignments['Assignment ID'].isin( + [id])].index, 'is_completed'] = True + update_csv(assignments) + except Exception: + click.echo('Failed to complete assignment #%s' % id) + sys.exit() + click.echo('Marked assignment #%s as complete' % id) + + @cli.command() + @click.argument('id') + def incomplete(id): + """ + Mark an assignment as incomplete by assignment ID + """ + credentials = get_data_from_file('studentvue_credentials', ',') + assignments = studentvue_parser.get_assignments(credentials) + try: + assignments.at[assignments.loc[assignments['Assignment ID'].isin( + [id])].index, 'is_completed'] = False + update_csv(assignments) + except Exception: + click.echo('Failed to mark assignment #%s as incomplete' % id) + sys.exit() + click.echo('Marked assignment #%s as incomplete' % id) + + @cli.command() + @click.argument('title') + @click.argument('date') + def add(title, date): + """ + Add a new assignment with the TITLE and DATE + """ + + # Get schedule + credentials = get_data_from_file('studentvue_credentials', ',') + classes = studentvue_parser.get_schedule(credentials) + valid = False + while not valid: + # Print all the classes + for class_ in classes: + print(class_) + + # Ask which period to add the assignment to + class_period_input = input( + '\nWhich class period do you want to add the assignment "%s" to? ' % + title) + try: # Check if the input can even be converted to an integer! + class_period = int(class_period_input) + except ValueError: + click.echo('"%s" is an invalid input' % class_period) + # Check that if the input is an integer, that it is a valid period + if class_period > len(classes) or class_period < 1: + click.echo("Invalid period.\n") + else: + valid = True + + # Auto generate the class name as if it was from Student Vue + teacher_fullname = classes[class_period - 1].teacher.name.split(' ') + teacher_label = '{0}, {1}'.format( + teacher_fullname[1], teacher_fullname[0][:1]) + class_name = '{0} {1}({2})'.format(teacher_label, + classes[class_period - 1].name, + classes[class_period - 1].period) + + # Generate a assignment list 8 digit id, and make sure it's unique + credentials = get_data_from_file('studentvue_credentials', ',') + assignments = studentvue_parser.get_assignments(credentials) + id_unique = False + + while not id_unique: + generated_id = random.randrange(11111111, 99999999, 1) + is_id_unique = True + for assignment_id in assignments["Assignment ID"]: + if assignment_id == generated_id: + is_id_unique = False + if is_id_unique: + id_unique = True + + # Make the assignment based on data we have collected/generated + assignment_df = pd.DataFrame({'Assignment ID': [generated_id], 'Class Name': [ + class_name], 'Due Date': [date], 'Assignment': [title], 'is_completed': ['False']}) + assignments = assignments.append(assignment_df, sort=True) + convert_dict = {'Assignment ID': int} + assignments = assignments.astype(convert_dict) + update_csv(assignments) + click.echo('Successfully added assignment "{0}"'.format(title)) + + # Execute command + cli(obj={}) + + +if __name__ == '__main__': + main() diff --git a/studentvue_parser.py b/studentvue_parser.py index d8c0f8a..a9f747e 100644 --- a/studentvue_parser.py +++ b/studentvue_parser.py @@ -21,7 +21,23 @@ def set_credentials(): return True +def get_stored_assignment_data(): + # Create CSV file if it doesn't exist + assignment_list.create_if_not_exist('studentvue_assignments.csv') + try: + stored_assignments = pd.read_csv(Path('data/studentvue_assignments.csv'), + sep='/') + except pd.io.common.EmptyDataError: + stored_assignments = pd.DataFrame({'Assignment ID': [], 'Class Name': [], 'Due Date': [ + ], 'Assignment': [], 'is_completed': []}) + click.echo('Invalid or empty file detected... discarding file') + convert_dict = {'Assignment ID': int} + stored_assignments = stored_assignments.astype(convert_dict) + return stored_assignments + + def get_assignments(credentials): + assignments = get_stored_assignment_data() # Login to Student Vue try: sv = StudentVue(credentials[0], credentials[1], credentials[2]) @@ -29,19 +45,9 @@ def get_assignments(credentials): click.echo( 'Invalid credentials. You might want to use:\n python assignment_list.py reset') sys.exit() - - # Create CSV file if it doesn't exist - assignment_list.create_if_not_exist('studentvue_assignments.csv') - try: - assignments = pd.read_csv(Path('data/studentvue_assignments.csv'), - sep='/') - except pd.io.common.EmptyDataError: - assignments = pd.DataFrame({'Assignment ID': [], 'Class Name': [], 'Due Date': [ - ], 'Assignment': [], 'is_completed': []}) - click.echo('Invalid or empty file detected... discarding file') try: studentvue_assignments = sv.get_assignments() - except BaseException: + except Exception: click.echo( 'Failed to get Student Vue assignments... Please see https://github.com/kajchang/StudentVue for help on ' 'this issue.') diff --git a/tests/list_added_none_test.py b/tests/list_added_none_test.py new file mode 100644 index 0000000..7aa9d74 --- /dev/null +++ b/tests/list_added_none_test.py @@ -0,0 +1,32 @@ +import sys +from io import StringIO + +import pandas as pd + +sys.path.append("") +import assignment_list + + +class Capturing(list): + def __enter__(self): + self._stdout = sys.stdout + sys.stdout = self._stringio = StringIO() + return self + + def __exit__(self, *args): + self.extend(self._stringio.getvalue().splitlines()) + del self._stringio # free up some memory + sys.stdout = self._stdout + + +def test_answer(): + assignments = pd.DataFrame({ + 'Assignment ID': ["1111111"], + 'Class Name': ["TESTCLASS"], + 'Due Date': ["1/1/2019"], + 'Assignment': ["Test assignment"], + 'is_completed': [False] + }) + with Capturing() as output: + assignment_list.list_added(assignments) + assert output == ['No assignments added yet.'] From a06c351217aa86222136d91cca640965aeddd948 Mon Sep 17 00:00:00 2001 From: Whodiduexpect <53096512+Whodiduexpect@users.noreply.github.com> Date: Sat, 29 Feb 2020 17:50:49 -0800 Subject: [PATCH 2/9] Update .travis.yml --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5662757..cbce3b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,13 @@ language: python os: - -osx -linux + -osx -windows python: - 3.6 - 3.7 -# command to install dependencies + - 3.8 install: - pip install -r requirements.txt -# command to run tests script: - pytest From 99eca635f70bf4d010691b775b26a24af4241722 Mon Sep 17 00:00:00 2001 From: Whodiduexpect <53096512+Whodiduexpect@users.noreply.github.com> Date: Sat, 29 Feb 2020 20:05:39 -0800 Subject: [PATCH 3/9] Delete .travis.yml --- .travis.yml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cbce3b1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: python -os: - -linux - -osx - -windows -python: - - 3.6 - - 3.7 - - 3.8 -install: - - pip install -r requirements.txt -script: - - pytest From e09a512d9d1c050a1e0b9b9512485b4d192ba34f Mon Sep 17 00:00:00 2001 From: Whodiduexpect <53096512+Whodiduexpect@users.noreply.github.com> Date: Sat, 29 Feb 2020 20:09:10 -0800 Subject: [PATCH 4/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cd36600..ba78d9a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/Whodiduexpect/assignment-list.svg?branch=master)](https://travis-ci.org/Whodiduexpect/assignment-list) +![Tests](https://github.com/Whodiduexpect/assignment-list/workflows/Tests/badge.svg) # Assignment List Assignment list is a terminal-based assignment manager for the Student Vue web portal. Assignment List is meant to replace the lack of features in Student Vue by giving tools to manage assignments, like a fancy integrated to-do list. If you just want a CLI Student Vue interface, [check out this neat project.](https://github.com/kajchang/studentvue-cli) From 27b15a0665986bf92a56de08b22319ba1cec05b7 Mon Sep 17 00:00:00 2001 From: Whodiduexpect <53096512+Whodiduexpect@users.noreply.github.com> Date: Sat, 29 Feb 2020 20:11:04 -0800 Subject: [PATCH 5/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba78d9a..3189c48 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Tests](https://github.com/Whodiduexpect/assignment-list/workflows/Tests/badge.svg) +https://github.com/Whodiduexpect/assignment-list/workflows/Tests/badge.svg # Assignment List Assignment list is a terminal-based assignment manager for the Student Vue web portal. Assignment List is meant to replace the lack of features in Student Vue by giving tools to manage assignments, like a fancy integrated to-do list. If you just want a CLI Student Vue interface, [check out this neat project.](https://github.com/kajchang/studentvue-cli) From 5c5326ed813cbd3e7741c342f939c65f23b1660c Mon Sep 17 00:00:00 2001 From: Whodiduexpect <53096512+Whodiduexpect@users.noreply.github.com> Date: Sat, 29 Feb 2020 20:12:10 -0800 Subject: [PATCH 6/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3189c48..ba78d9a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -https://github.com/Whodiduexpect/assignment-list/workflows/Tests/badge.svg +![Tests](https://github.com/Whodiduexpect/assignment-list/workflows/Tests/badge.svg) # Assignment List Assignment list is a terminal-based assignment manager for the Student Vue web portal. Assignment List is meant to replace the lack of features in Student Vue by giving tools to manage assignments, like a fancy integrated to-do list. If you just want a CLI Student Vue interface, [check out this neat project.](https://github.com/kajchang/studentvue-cli) From 27360d9075c5608c3694b219b62fa35c0570f99d Mon Sep 17 00:00:00 2001 From: Whodiduexpect <53096512+Whodiduexpect@users.noreply.github.com> Date: Sat, 29 Feb 2020 20:13:03 -0800 Subject: [PATCH 7/9] Fix a few (mostly style) issues --- assignment_list.py | 279 +++++++++++++++++++++++---------------------- 1 file changed, 142 insertions(+), 137 deletions(-) diff --git a/assignment_list.py b/assignment_list.py index 6df44bd..b19599e 100644 --- a/assignment_list.py +++ b/assignment_list.py @@ -32,9 +32,11 @@ def list_completed(assignments): else: click.echo(assignments_view) + def list_added(assignments): assignments_view = assignments.drop(columns=['is_completed']) - assignments_view['Assignment ID'] = assignments['Assignment ID'].astype('str') + assignments_view['Assignment ID'] = assignments['Assignment ID'].astype( + 'str') mask = (assignments_view['Assignment ID'].str.len() == 8) assignments_view = assignments_view.loc[mask] if assignments_view.empty: @@ -63,7 +65,145 @@ def create_if_not_exist(filename): file.close() -# Main +# Define commands +@click.group() +def cli(): + """ + A Student Vue assignment manager + """ + + +@cli.command() +def reset(): + """ + Reset credentials + """ + studentvue_parser.set_credentials() + + +@cli.command() +@click.argument('category', required=False) +def list(category): + """ + List assignments by CATEGORY (defaults to 'current') + """ + if not category: + category = 'current' + if category == 'current': + credentials = get_data_from_file('studentvue_credentials', ',') + assignments = studentvue_parser.get_assignments(credentials) + list_assignments(assignments) + elif category == 'completed': + assignments = studentvue_parser.get_stored_assignment_data() + list_completed(assignments) + elif category == 'added': + assignments = studentvue_parser.get_stored_assignment_data() + list_added(assignments) + else: + click.echo( + '"%s" is not a valid category. The categories are "current" and "completed"' % + category) + + +@cli.command() +@click.argument('id') +def complete(id): + """ + Complete an assignment by assignment ID + """ + credentials = get_data_from_file('studentvue_credentials', ',') + assignments = studentvue_parser.get_assignments(credentials) + try: + assignments.at[assignments.loc[assignments['Assignment ID'].isin( + [id])].index, 'is_completed'] = True + update_csv(assignments) + except Exception: + click.echo('Failed to complete assignment #%s' % id) + sys.exit() + click.echo('Marked assignment #%s as complete' % id) + + +@cli.command() +@click.argument('id') +def incomplete(id): + """ + Mark an assignment as incomplete by assignment ID + """ + credentials = get_data_from_file('studentvue_credentials', ',') + assignments = studentvue_parser.get_assignments(credentials) + try: + assignments.at[assignments.loc[assignments['Assignment ID'].isin( + [id])].index, 'is_completed'] = False + update_csv(assignments) + except Exception: + click.echo('Failed to mark assignment #%s as incomplete' % id) + sys.exit() + click.echo('Marked assignment #%s as incomplete' % id) + + +@cli.command() +@click.argument('title') +@click.argument('date') +def add(title, date): + """ + Add a new assignment with the TITLE and DATE + """ + + # Get schedule + credentials = get_data_from_file('studentvue_credentials', ',') + classes = studentvue_parser.get_schedule(credentials) + valid = False + while not valid: + # Print all the classes + for class_ in classes: + print(class_) + + # Ask which period to add the assignment to + class_period_input = input( + '\nWhich class period do you want to add the assignment "%s" to? ' % + title) + try: # Check if the input can even be converted to an integer! + class_period = int(class_period_input) + except ValueError: + click.echo('"%s" is an invalid input' % class_period) + # Check that if the input is an integer, that it is a valid period + if class_period > len(classes) or class_period < 1: + click.echo("Invalid period.\n") + else: + valid = True + + # Auto generate the class name as if it was from Student Vue + teacher_fullname = classes[class_period - 1].teacher.name.split(' ') + teacher_label = '{0}, {1}'.format( + teacher_fullname[1], teacher_fullname[0][:1]) + class_name = '{0} {1}({2})'.format(teacher_label, + classes[class_period - 1].name, + classes[class_period - 1].period) + + # Generate a assignment list 8 digit id, and make sure it's unique + credentials = get_data_from_file('studentvue_credentials', ',') + assignments = studentvue_parser.get_assignments(credentials) + id_unique = False + + while not id_unique: + generated_id = random.randrange(11111111, 99999999, 1) + is_id_unique = True + for assignment_id in assignments["Assignment ID"]: + if assignment_id == generated_id: + is_id_unique = False + if is_id_unique: + id_unique = True + + # Make the assignment based on data we have collected/generated + assignment_df = pd.DataFrame({'Assignment ID': [generated_id], 'Class Name': [ + class_name], 'Due Date': [date], 'Assignment': [title], 'is_completed': ['False']}) + assignments = assignments.append(assignment_df, sort=True) + convert_dict = {'Assignment ID': int} + assignments = assignments.astype(convert_dict) + update_csv(assignments) + click.echo('Successfully added assignment "{0}"'.format(title)) + + def main(): # If the credential file does not exist: if not os.path.exists(Path('data/studentvue_credentials')): @@ -74,141 +214,6 @@ def main(): # Now that we know we have a data folder, let's set the credentials studentvue_parser.set_credentials() - # Read the credential file - - # Define commands - @click.group() - def cli(): - """ - A Student Vue assignment manager - """ - - @cli.command() - def reset(): - """ - Reset credentials - """ - studentvue_parser.set_credentials() - - @cli.command() - @click.argument('category', required=False) - def list(category): - """ - List assignments by CATEGORY (defaults to 'current') - """ - if not category: - category = 'current' - if category == 'current': - credentials = get_data_from_file('studentvue_credentials', ',') - assignments = studentvue_parser.get_assignments(credentials) - list_assignments(assignments) - elif category == 'completed': - assignments = studentvue_parser.get_stored_assignment_data() - list_completed(assignments) - elif category == 'added': - assignments = studentvue_parser.get_stored_assignment_data() - list_added(assignments) - else: - click.echo( - '"%s" is not a valid category. The categories are "current" and "completed"' % - category) - - @cli.command() - @click.argument('id') - def complete(id): - """ - Complete an assignment by assignment ID - """ - credentials = get_data_from_file('studentvue_credentials', ',') - assignments = studentvue_parser.get_assignments(credentials) - try: - assignments.at[assignments.loc[assignments['Assignment ID'].isin( - [id])].index, 'is_completed'] = True - update_csv(assignments) - except Exception: - click.echo('Failed to complete assignment #%s' % id) - sys.exit() - click.echo('Marked assignment #%s as complete' % id) - - @cli.command() - @click.argument('id') - def incomplete(id): - """ - Mark an assignment as incomplete by assignment ID - """ - credentials = get_data_from_file('studentvue_credentials', ',') - assignments = studentvue_parser.get_assignments(credentials) - try: - assignments.at[assignments.loc[assignments['Assignment ID'].isin( - [id])].index, 'is_completed'] = False - update_csv(assignments) - except Exception: - click.echo('Failed to mark assignment #%s as incomplete' % id) - sys.exit() - click.echo('Marked assignment #%s as incomplete' % id) - - @cli.command() - @click.argument('title') - @click.argument('date') - def add(title, date): - """ - Add a new assignment with the TITLE and DATE - """ - - # Get schedule - credentials = get_data_from_file('studentvue_credentials', ',') - classes = studentvue_parser.get_schedule(credentials) - valid = False - while not valid: - # Print all the classes - for class_ in classes: - print(class_) - - # Ask which period to add the assignment to - class_period_input = input( - '\nWhich class period do you want to add the assignment "%s" to? ' % - title) - try: # Check if the input can even be converted to an integer! - class_period = int(class_period_input) - except ValueError: - click.echo('"%s" is an invalid input' % class_period) - # Check that if the input is an integer, that it is a valid period - if class_period > len(classes) or class_period < 1: - click.echo("Invalid period.\n") - else: - valid = True - - # Auto generate the class name as if it was from Student Vue - teacher_fullname = classes[class_period - 1].teacher.name.split(' ') - teacher_label = '{0}, {1}'.format( - teacher_fullname[1], teacher_fullname[0][:1]) - class_name = '{0} {1}({2})'.format(teacher_label, - classes[class_period - 1].name, - classes[class_period - 1].period) - - # Generate a assignment list 8 digit id, and make sure it's unique - credentials = get_data_from_file('studentvue_credentials', ',') - assignments = studentvue_parser.get_assignments(credentials) - id_unique = False - - while not id_unique: - generated_id = random.randrange(11111111, 99999999, 1) - is_id_unique = True - for assignment_id in assignments["Assignment ID"]: - if assignment_id == generated_id: - is_id_unique = False - if is_id_unique: - id_unique = True - - # Make the assignment based on data we have collected/generated - assignment_df = pd.DataFrame({'Assignment ID': [generated_id], 'Class Name': [ - class_name], 'Due Date': [date], 'Assignment': [title], 'is_completed': ['False']}) - assignments = assignments.append(assignment_df, sort=True) - convert_dict = {'Assignment ID': int} - assignments = assignments.astype(convert_dict) - update_csv(assignments) - click.echo('Successfully added assignment "{0}"'.format(title)) - # Execute command cli(obj={}) From 0d8229e1ae11ec991e140e97bb9ac30e4c092f4f Mon Sep 17 00:00:00 2001 From: Whodiduexpect <53096512+Whodiduexpect@users.noreply.github.com> Date: Sat, 29 Feb 2020 20:21:44 -0800 Subject: [PATCH 8/9] Update USAGE.md --- USAGE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/USAGE.md b/USAGE.md index 8532228..5af770d 100644 --- a/USAGE.md +++ b/USAGE.md @@ -87,9 +87,9 @@ Marked assignment #1111111 as complete ``` # The `list` command -The `list` command lists the assignments. Currently, it has 2 optional categories, which are `current` and `completed`. The reason these categories are optional is that by default it's `current`, as to not require an unnecessary long command. +The `list` command lists the assignments. Currently, it has 3 optional categories, which are `current`, `completed`, and `added` (assignments added via the `add` command). The reason these categories are optional is that by default it's `current`, as to not require an unnecessary long command. ## Example Usage -`python assignment_list.py list` OR `python assignment_list.py list current` +`python assignment_list.py list` or `python assignment_list.py list current` ``` Assignment Assignment ID Class Name Due Date 0 Test Assignment #1 1111111 Last, F TESTCLASS I(1) 1/01/2019 From bf684b504b6e0069936a15d73d84935259831679 Mon Sep 17 00:00:00 2001 From: Whodiduexpect <53096512+Whodiduexpect@users.noreply.github.com> Date: Sat, 29 Feb 2020 20:22:32 -0800 Subject: [PATCH 9/9] Update usage.md --- docs/usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage.md b/docs/usage.md index 07cf0f5..380d948 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -80,7 +80,7 @@ Marked assignment #1111111 as complete ``` ## The list command -The `list` command lists the assignments. Currently, it has 2 optional categories, which are `current` and `completed`. The reason these categories are optional is that by default it's `current`, as to not require an unnecessary long command. +The `list` command lists the assignments. Currently, it has 3 optional categories, which are `current`, `completed`, and `added` (assignments added via the `add` command). The reason these categories are optional is that by default it's `current`, as to not require an unnecessary long command. ### Example Usage