Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Fix style and typo in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Whodiduexpect committed Oct 9, 2019
1 parent 14f25d1 commit c7f3202
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 55 deletions.
72 changes: 37 additions & 35 deletions assignment_list.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/usr/bin/env python3
import sys
import os
import random
import sys
from pathlib import Path

import click
import pandas as pd
from pathlib import Path

import studentvue_parser
import random


# Define functions
def openData(file, mode):
def open_data(file, mode):
return open(Path('data/%s' % file), mode)


def listAssignments(assignments):
def list_assignments(assignments):
if not len(assignments):
click.echo('No assignments to do!')
else:
Expand All @@ -22,7 +24,7 @@ def listAssignments(assignments):
click.echo(assignments_view)


def listCompleted(assignments):
def list_completed(assignments):
if not len(assignments):
click.echo('No assignments completed yet.')
else:
Expand All @@ -31,27 +33,27 @@ def listCompleted(assignments):
click.echo(assignments_view)


def getDataFromFile(filename, split_char):
file = openData(filename, 'r')
def get_data_from_file(filename, split_char):
file = open_data(filename, 'r')
output = file.read().split(split_char)
file.close()
return output


def updateCsv(assignments):
def update_csv(assignments):
assignments.to_csv(
Path('data/studentvue_assignments.csv'),
sep='/',
index=False)


def createIfNotExist(filename):
def create_if_not_exist(filename):
if not os.path.exists(Path('data/%s' % filename)):
file = openData(filename, 'w')
file = open_data(filename, 'w')
file.close()


def pointProblematicFile(path):
def point_problematic_file(path):
click.echo('Full path to problematic file: %s' % Path(path).absolute())


Expand All @@ -64,39 +66,39 @@ def main():
# Create one
os.mkdir('data')
# Now that we know we have a data folder, let's set the credentials
studentvue_parser.setCredentials()
studentvue_parser.set_credentials()

# Read the credential file
credentials = getDataFromFile('studentvue_credentials', ',')
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.setCredentials()
"""
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.getAssignments(credentials)
listAssignments(assignments)
assignments = studentvue_parser.get_assignments(credentials)
list_assignments(assignments)
elif category == 'completed':
assignments = studentvue_parser.getAssignments(credentials)
listCompleted(assignments)
assignments = studentvue_parser.get_assignments(credentials)
list_completed(assignments)
else:
click.echo(
'"%s" is not a valid category. Currently, the only valid category is current' %
Expand All @@ -105,26 +107,26 @@ def list(category):
@cli.command()
@click.argument('id')
def complete(id):
'''
"""
Complete an assignment by assignment ID
'''
assignments = studentvue_parser.getAssignments(credentials)
"""
assignments = studentvue_parser.get_assignments(credentials)
try:
assignments.at[assignments.loc[assignments['Assignment ID'].isin(
[id])].index, 'is_completed'] = True
updateCsv(assignments)
update_csv(assignments)
except BaseException:
click.echo('Failed to complete assignemnt #%s' % id)
click.echo('Failed to complete assignment #%s' % id)
sys.exit()
click.echo('Marked assignment #%s as complete' % 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.getSchedule(credentials)
Expand Down Expand Up @@ -160,7 +162,7 @@ def add(title, date):
classes[class_period - 1].period)

# Generate a assignment list 8 digit id, and make sure it's unique
assignments = studentvue_parser.getAssignments(credentials)
assignments = studentvue_parser.get_assignments(credentials)
id_unique = False

while not id_unique:
Expand All @@ -174,11 +176,11 @@ def add(title, date):

# 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']})
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)
updateCsv(assignments)
update_csv(assignments)
click.echo('Successfully added assignment "{0}"'.format(title))

# Execute command
Expand Down
23 changes: 11 additions & 12 deletions studentvue_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
from getpass import getpass


def setCredentials():
assignment_list.createIfNotExist('studentvue_credentials')
def set_credentials():
assignment_list.create_if_not_exist('studentvue_credentials')
click.echo('-- Credentials setup/reset --')
student_id = input('Please enter Student ID: ')
password = getpass('Please enter password (hidden): ')
district_url = input('Please enter district login url: ')
file = assignment_list.openData('studentvue_credentials', 'w')
file = assignment_list.open_data('studentvue_credentials', 'w')
file.write(student_id + ',' + password + ',' + district_url)
file.close()
return True


def getAssignments(credentials):
def get_assignments(credentials):
# Login to Student Vue
try:
sv = StudentVue(credentials[0], credentials[1], credentials[2])
Expand All @@ -28,22 +28,21 @@ def getAssignments(credentials):
'Invalid credentials. You might want to use:\n python assignment_list.py reset')
sys.exit()

# Create CSV file if it dosen't exist
assignment_list.createIfNotExist('studentvue_assignments.csv')
assignments = []
# 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'), # reads 'assignment_id', 'class_name', 'date', 'name', 'is_completed'
assignments = pd.read_csv(Path('data/studentvue_assignments.csv'),
sep='/')
except BaseException:
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 Exception as e:
except BaseException:
click.echo(
'Failed to get Student Vue assignments... Please see https://github.com/kajchang/StudentVue for help on this issue.\n The specific error is:',
sys.exc_info()[1])
'Failed to get Student Vue assignments... Please see https://github.com/kajchang/StudentVue for help on '
'this issue.')
sys.exit()
found_duplicate = False
for sv_assignment in studentvue_assignments:
Expand All @@ -63,7 +62,7 @@ def getAssignments(credentials):
assignments = assignments.append(assignment_df, sort=True)
convert_dict = {'Assignment ID': int}
assignments = assignments.astype(convert_dict)
assignment_list.updateCsv(assignments)
assignment_list.update_csv(assignments)
return assignments


Expand Down
6 changes: 3 additions & 3 deletions tests/help_screen_test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import pytest
import os
import subprocess
import sys
import os

sys.path.append("")
import assignment_list


def test_answer():
if not os.path.exists("data"):
os.mkdir("data")
assignment_list.createIfNotExist("studentvue_credentials")
assignment_list.create_if_not_exist("studentvue_credentials")
result = subprocess.run(
['python3', 'assignment_list.py'], stdout=subprocess.PIPE)
assert "Usage:" in result.stdout.decode("utf-8")
10 changes: 5 additions & 5 deletions tests/invalid_credentials_test.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import pytest
import os
import subprocess
import sys
import os

sys.path.append('')
import assignment_list


def test_answer():
if not os.path.exists('data'):
os.mkdir('data')
file = assignment_list.openData('studentvue_credentials', 'r')
file = assignment_list.open_data('studentvue_credentials', 'r')
contents = file.read()
file.close()
file = assignment_list.openData('studentvue_credentials', 'w+')
file = assignment_list.open_data('studentvue_credentials', 'w+')
file.close()
result = subprocess.run(
['python3', 'assignment_list.py', 'list'], stdout=subprocess.PIPE)
file = assignment_list.openData('studentvue_credentials', 'w+')
file = assignment_list.open_data('studentvue_credentials', 'w+')
file.write(contents)
file.close()
assert "python assignment_list.py reset" in result.stdout.decode("utf-8")

0 comments on commit c7f3202

Please sign in to comment.