mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
cleaned up code in skoolos.py
This commit is contained in:
parent
11c0c03bae
commit
1c2a344cce
60
skoolos.py
60
skoolos.py
|
@ -77,7 +77,7 @@ def main():
|
|||
},
|
||||
]
|
||||
u = int(prompt(user)['user'].split(")")[0]) - 1
|
||||
if(u+1 == count):
|
||||
if u + 1 == count:
|
||||
authenticate()
|
||||
return
|
||||
data = info[u]
|
||||
|
@ -89,6 +89,7 @@ def main():
|
|||
else:
|
||||
teacherCLI(USER, PWD)
|
||||
|
||||
|
||||
#################################################################################################### STUDENT METHODS
|
||||
|
||||
def studentCLI(user, password):
|
||||
|
@ -104,7 +105,7 @@ def studentCLI(user, password):
|
|||
EXIT = False
|
||||
while not EXIT:
|
||||
course = chooseClassStudent(student)
|
||||
if(course == "Exit SkoolOS"):
|
||||
if course == "Exit SkoolOS":
|
||||
return
|
||||
EXIT = classOptionsStudent(student, course)
|
||||
|
||||
|
@ -171,6 +172,11 @@ def classOptionsStudent(student, course):
|
|||
|
||||
#################################################################################################### TEACHER METHODS
|
||||
def teacherCLI(user, password):
|
||||
"""
|
||||
The CLI for teachers to access
|
||||
:param user: teachers username
|
||||
:param password: teachers password
|
||||
"""
|
||||
from CLI import teacher
|
||||
data = getUser(user, password, 'teacher')
|
||||
print(data)
|
||||
|
@ -181,7 +187,7 @@ def teacherCLI(user, password):
|
|||
# 3. Get progress logs on a student
|
||||
# 2. make an assignment for a class
|
||||
# 3. view student submissions for an assignment
|
||||
while(not EXIT):
|
||||
while not EXIT:
|
||||
# Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"
|
||||
course = chooseGeneralTeacher(teacher)
|
||||
if course == "Exit SkoolOS":
|
||||
|
@ -191,15 +197,16 @@ def teacherCLI(user, password):
|
|||
# selected a class
|
||||
else:
|
||||
option = classOptionsTeacher(teacher, course)
|
||||
if(option == '1'):
|
||||
if option == '1':
|
||||
EXIT = addStudentsTeacher(teacher, course)
|
||||
elif(option == '2'):
|
||||
elif option == '2':
|
||||
EXIT = addAssignmentTeacher(teacher, course)
|
||||
elif(option == '3'):
|
||||
elif option == '3':
|
||||
EXIT = viewStudentsTeacher(teacher, course)
|
||||
else:
|
||||
EXIT = True
|
||||
|
||||
|
||||
def chooseGeneralTeacher(teacher):
|
||||
carray = []
|
||||
for c in teacher.classes:
|
||||
|
@ -217,6 +224,7 @@ def chooseGeneralTeacher(teacher):
|
|||
course = prompt(courses)['course']
|
||||
return course
|
||||
|
||||
|
||||
def makeClassTeacher(teacher):
|
||||
questions = [
|
||||
{
|
||||
|
@ -227,7 +235,7 @@ def makeClassTeacher(teacher):
|
|||
]
|
||||
cname = prompt(questions)['cname']
|
||||
print(cname)
|
||||
while(not ("_" + teacher.username) in cname):
|
||||
while not ("_" + teacher.username) in cname:
|
||||
print("Incorrect naming format")
|
||||
questions = [
|
||||
{
|
||||
|
@ -249,14 +257,14 @@ def makeClassTeacher(teacher):
|
|||
},
|
||||
]
|
||||
choice = prompt(questions)['students'].split(")")[0]
|
||||
if("1" == choice):
|
||||
if "1" == choice:
|
||||
s = input("Student name: ")
|
||||
teacher.addStudent(s, cname)
|
||||
if("2" == choice):
|
||||
if "2" == choice:
|
||||
print("File must be .txt and have 1 student username per line")
|
||||
path = input("Relative Path: ")
|
||||
while(not os.path.exists(path)):
|
||||
if(path == 'N'):
|
||||
while not os.path.exists(path):
|
||||
if path == 'N':
|
||||
return True
|
||||
print(path + " is not a valid path")
|
||||
path = input("Enter file path ('N' to exit): ")
|
||||
|
@ -265,6 +273,7 @@ def makeClassTeacher(teacher):
|
|||
teacher.reqAddStudentList(students, cname)
|
||||
return False
|
||||
|
||||
|
||||
def classOptionsTeacher(teacher, course):
|
||||
print("Class: " + course)
|
||||
unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed']
|
||||
|
@ -282,6 +291,7 @@ def classOptionsTeacher(teacher, course):
|
|||
option = prompt(questions)['course'].split(")")[0]
|
||||
return option
|
||||
|
||||
|
||||
def addStudentsTeacher(teacher, course):
|
||||
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
||||
questions = [
|
||||
|
@ -293,7 +303,7 @@ def addStudentsTeacher(teacher, course):
|
|||
},
|
||||
]
|
||||
schoice = prompt(questions)['students'].split(")")[0]
|
||||
if(schoice == '1'):
|
||||
if schoice == '1':
|
||||
questions = [
|
||||
{
|
||||
'type': 'input',
|
||||
|
@ -304,7 +314,7 @@ def addStudentsTeacher(teacher, course):
|
|||
s = prompt(questions)['student']
|
||||
teacher.reqStudent(s, course)
|
||||
return False
|
||||
if(schoice == '2'):
|
||||
if schoice == '2':
|
||||
questions = [
|
||||
{
|
||||
'type': 'input',
|
||||
|
@ -313,8 +323,8 @@ def addStudentsTeacher(teacher, course):
|
|||
},
|
||||
]
|
||||
path = prompt(questions)['path']
|
||||
while(not os.path.exists(path)):
|
||||
if(path == 'N'):
|
||||
while not os.path.exists(path):
|
||||
if path == 'N':
|
||||
sys.exit(0)
|
||||
print(path + " is not a valid path")
|
||||
path = input("Enter file path ('N' to exit): ")
|
||||
|
@ -325,6 +335,7 @@ def addStudentsTeacher(teacher, course):
|
|||
else:
|
||||
return True
|
||||
|
||||
|
||||
def addAssignmentTeacher(teacher, course):
|
||||
nlist = os.listdir(teacher.username + "/" + course)
|
||||
alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments']
|
||||
|
@ -335,19 +346,19 @@ def addAssignmentTeacher(teacher, course):
|
|||
b = True
|
||||
print(teacher.username + "/" + course + "/" + n)
|
||||
for a in alist:
|
||||
if(n in a or n == a):
|
||||
if n in a or n == a:
|
||||
# print("Assignments: " + n)
|
||||
b = False
|
||||
if(not os.path.isdir(teacher.username + "/" + course + "/" + n)):
|
||||
if not os.path.isdir(teacher.username + "/" + course + "/" + n):
|
||||
b = False
|
||||
if(b):
|
||||
if b:
|
||||
tlist.append(n)
|
||||
|
||||
|
||||
nlist = tlist
|
||||
if(len(nlist) == 0):
|
||||
if len(nlist) == 0:
|
||||
print("No new assignments found")
|
||||
print("To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder")
|
||||
print(
|
||||
"To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder")
|
||||
return False
|
||||
questions = [
|
||||
{
|
||||
|
@ -363,7 +374,7 @@ def addAssignmentTeacher(teacher, course):
|
|||
due = due + ":33.383124"
|
||||
due = due.strip()
|
||||
f = False
|
||||
while(not f):
|
||||
while not f:
|
||||
try:
|
||||
datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
||||
f = True
|
||||
|
@ -375,6 +386,7 @@ def addAssignmentTeacher(teacher, course):
|
|||
teacher.addAssignment(apath, course, due)
|
||||
return False
|
||||
|
||||
|
||||
def viewStudentsTeacher(teacher, course):
|
||||
data = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/classes/" + course)
|
||||
students = data["confirmed"]
|
||||
|
@ -386,7 +398,7 @@ def viewStudentsTeacher(teacher, course):
|
|||
for s in unconf:
|
||||
print(s)
|
||||
student = input("View student (Enter student's ion username): ")
|
||||
while((not student in str(data['confirmed'])) or (not student in str(data['unconfirmed']))):
|
||||
while (not student in str(data['confirmed'])) or (not student in str(data['unconfirmed'])):
|
||||
print("Student not affiliated with class")
|
||||
student = input("View student ('N' to exit): ")
|
||||
if student == 'N':
|
||||
|
@ -394,7 +406,6 @@ def viewStudentsTeacher(teacher, course):
|
|||
print(getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/"))
|
||||
|
||||
|
||||
|
||||
############################################################################################################################################
|
||||
|
||||
|
||||
|
@ -427,6 +438,7 @@ def getUser(ion_user, password, utype):
|
|||
print(r.status_code)
|
||||
return None
|
||||
|
||||
|
||||
def patchDB(USER, PWD, url, data):
|
||||
r = requests.patch(url=url, data=data, auth=(USER, PWD))
|
||||
print("PATH:" + str(r.status_code))
|
||||
|
|
Loading…
Reference in New Issue
Block a user