mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-11 07:50:18 -04:00
Merge branch 'development' of https://github.com/Rushilwiz/SkoolOS into development
This commit is contained in:
commit
867e76a01c
|
@ -32,8 +32,11 @@ def getStudent(ion_user, password):
|
|||
#makes a GET request to given url, returns dict
|
||||
def getDB(user, pwd, url):
|
||||
"""
|
||||
Sends a GET request to the URL
|
||||
Sends a GET request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.get(url=url, auth=(user, pwd))
|
||||
print("GET:" + str(r.status_code))
|
||||
|
@ -42,9 +45,12 @@ def getDB(user, pwd, url):
|
|||
#makes a PATCH (updates instance) request to given url, returns dict
|
||||
def patchDB(user, pwd, data, url):
|
||||
"""
|
||||
Sends a PATCH request to the URL
|
||||
:param data:
|
||||
Sends a PATCH request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
:param data: data to request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.patch(url=url, data=data, auth=(user, pwd))
|
||||
print("PATCH:" + str(r.status_code))
|
||||
|
@ -54,9 +60,12 @@ def patchDB(user, pwd, data, url):
|
|||
#makes a POST (makes new instance) request to given url, returns dict
|
||||
def postDB(user, pwd, data, url):
|
||||
"""
|
||||
Sends a POST request to the URL
|
||||
:param data:
|
||||
Sends a POST request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
:param data: data to request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.post(url=url, data=data, auth=(user, pwd))
|
||||
print("POST:" + str(r.status_code))
|
||||
|
@ -66,10 +75,13 @@ def postDB(user, pwd, data, url):
|
|||
#makes a PUT (overwrites instance) request to given url, returns dict
|
||||
def putDB(user, pwd, data, url):
|
||||
"""
|
||||
Sends a PUT request to the URL
|
||||
:param data:
|
||||
Sends a PUT request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
"""
|
||||
:param data: data to request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.put(url=url, data=data, auth=(user, pwd))
|
||||
print("PUT:" + str(r.status_code))
|
||||
return r.json()
|
||||
|
@ -78,8 +90,11 @@ def putDB(user, pwd, data, url):
|
|||
#makes a DELETE (delete instance) request to given url, returns dict
|
||||
def delDB(user, pwd, url):
|
||||
"""
|
||||
Sends a DELETE request to the URL
|
||||
Sends a DELETE request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.delete(url=url, auth=(user, pwd))
|
||||
print("DELETE:" + str(r.status_code))
|
||||
|
@ -112,6 +127,7 @@ class Student:
|
|||
self.completed = data['completed']
|
||||
self.user = data['user']
|
||||
self.password = password
|
||||
self.completed = data['completed']
|
||||
# classes in id form (Example: 4,5)
|
||||
# storing actual classes
|
||||
cid = data['classes'].split(",")
|
||||
|
@ -385,12 +401,13 @@ class Student:
|
|||
command("git add .")
|
||||
command("git commit -m update")
|
||||
command('git checkout ' + course)
|
||||
time.sleep(5)
|
||||
ass = os.listdir()
|
||||
oname = ''
|
||||
inclass = False
|
||||
for a in ass:
|
||||
if a == assignment:
|
||||
if a in assignment:
|
||||
inclass = True
|
||||
oname = a + "_" + course
|
||||
break
|
||||
if (inclass == False):
|
||||
print(assignment + " not an assignment of " + course)
|
||||
|
@ -404,6 +421,11 @@ class Student:
|
|||
command("git tag " + assignment + "-final")
|
||||
command("git push -u origin " + course + " --tags")
|
||||
command('git checkout master')
|
||||
self.completed = assignment + "," + self.completed
|
||||
data = {
|
||||
'completed': self.completed
|
||||
}
|
||||
patchDB(self.username, self.password, data, self.url)
|
||||
os.chdir(cdir)
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ def getTeacher(ion_user, password):
|
|||
"""
|
||||
Gets information about a teacher from the api
|
||||
:param ion_user: a teacher
|
||||
:param password: a string
|
||||
:param password: the teacher's password
|
||||
:return: teacher information or error
|
||||
"""
|
||||
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
||||
|
@ -52,10 +52,11 @@ def getTeacher(ion_user, password):
|
|||
#makes a GET request to given url, returns dict
|
||||
def getDB(user, pwd, url):
|
||||
"""
|
||||
Sends a GET request to the URL
|
||||
:param user: a string
|
||||
:param password: a string
|
||||
Sends a GET request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.get(url=url, auth=(user, pwd))
|
||||
print("GET:" + str(r.status_code))
|
||||
|
@ -64,11 +65,12 @@ def getDB(user, pwd, url):
|
|||
#makes a PATCH (updates instance) request to given url, returns dict
|
||||
def patchDB(user, pwd, data, url):
|
||||
"""
|
||||
Sends a PATCH request to the URL
|
||||
:param data:
|
||||
:param user: a string
|
||||
:param password: a string
|
||||
Sends a PATCH request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
:param data: data to request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.patch(url=url, data=data, auth=(user, pwd))
|
||||
print("PATCH:" + str(r.status_code))
|
||||
|
@ -78,11 +80,12 @@ def patchDB(user, pwd, data, url):
|
|||
#makes a POST (makes new instance) request to given url, returns dict
|
||||
def postDB(user, pwd, data, url):
|
||||
"""
|
||||
Sends a POST request to the URL
|
||||
:param data:
|
||||
:param user: a string
|
||||
:param password: a string
|
||||
Sends a POST request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
:param data: data to request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.post(url=url, data=data, auth=(user, pwd))
|
||||
print("POST:" + str(r.status_code))
|
||||
|
@ -92,10 +95,12 @@ def postDB(user, pwd, data, url):
|
|||
#makes a PUT (overwrites instance) request to given url, returns dict
|
||||
def putDB(user, pwd, data, url):
|
||||
"""
|
||||
Sends a PUT request to the URL
|
||||
:param user: a string
|
||||
:param password: a string
|
||||
Sends a PUT request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
:param data: data to request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.put(url=url, data=data, auth=(user, pwd))
|
||||
print("PUT:" + str(r.status_code))
|
||||
|
@ -105,10 +110,11 @@ def putDB(user, pwd, data, url):
|
|||
#makes a DELETE (delete instance) request to given url, returns dict
|
||||
def delDB(user, pwd, url):
|
||||
"""
|
||||
Sends a DELETE request to the URL
|
||||
:param user: a string
|
||||
:param password: a string
|
||||
Sends a DELETE request to url
|
||||
:param user: username
|
||||
:param pwd: password
|
||||
:param url: URL for request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.delete(url=url, auth=(user, pwd))
|
||||
print("DELETE:" + str(r.status_code))
|
||||
|
@ -152,6 +158,13 @@ class Teacher:
|
|||
self.classes = data['classes']
|
||||
if os.path.isdir(self.username + "/Students"):
|
||||
print("Synced to " + self.username)
|
||||
existing_classes = os.listdir(self.username)
|
||||
for c in self.classes:
|
||||
if not c in str(existing_classes):
|
||||
os.mkdir(self.username + "/" + c)
|
||||
print("Updated: " + c)
|
||||
command("touch " + self.username + "/" + c + "/README.md")
|
||||
|
||||
else:
|
||||
os.makedirs(self.username + "/Students")
|
||||
|
||||
|
@ -604,7 +617,7 @@ class Teacher:
|
|||
|
||||
# pull student's work, no modifications
|
||||
def getStudents(self, course):
|
||||
if not (course in self.sclass):
|
||||
if not (course in str(self.classes)):
|
||||
print(course + " not a class.")
|
||||
return
|
||||
path = self.username + "/Students/" + course
|
||||
|
@ -697,7 +710,7 @@ class Teacher:
|
|||
# 'classes':course
|
||||
# }
|
||||
log = self.getCommits(student, course, 30)
|
||||
assignment['due_date'] = datetime.strptime(assignment['due_date'], '%Y-%m-%d %H:%M:%S.%f')
|
||||
assignment['due_date'] = datetime.strptime(assignment['due_date'], '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||
late = False
|
||||
cdir = os.getcwd()
|
||||
os.chdir(self.username + "/Students/" + course + "/" + student)
|
||||
|
@ -727,7 +740,7 @@ class Teacher:
|
|||
|
||||
# data = getTeacher("eharris1","PWD")
|
||||
# print(data)
|
||||
# t = Teacher(data, "PWD")
|
||||
#t = Teacher(data, "PWD")
|
||||
# t.makeClass("APLit_eharris1")
|
||||
# t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124')
|
||||
# ar = ['2022rkhondak','2022inafi','2023rumareti']
|
||||
|
|
0
eharris1/English12_eharris1/Essay1/instruct.txt
Normal file
0
eharris1/English12_eharris1/Essay1/instruct.txt
Normal file
0
eharris1/History12_eharris1/README.md
Normal file
0
eharris1/History12_eharris1/README.md
Normal file
527
skoolos.py
527
skoolos.py
|
@ -25,7 +25,12 @@ scope = ["read"]
|
|||
USER = ""
|
||||
PWD = ""
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
The Command Line Interface (CLI) for SkoolOS
|
||||
Serves to allow both teachers and students to access the majority of the features of SkoolOS
|
||||
"""
|
||||
print("")
|
||||
print("░██████╗██╗░░██╗░█████╗░░█████╗░██╗░░░░░ ░█████╗░░██████╗")
|
||||
print("██╔════╝██║░██╔╝██╔══██╗██╔══██╗██║░░░░░ ██╔══██╗██╔════╝")
|
||||
|
@ -40,13 +45,13 @@ def main():
|
|||
if not ("profile" in str(profiles)):
|
||||
try:
|
||||
URL = "http://127.0.0.1:8000/api/"
|
||||
r = requests.get(url = URL)
|
||||
r = requests.get(url=URL)
|
||||
except:
|
||||
print("Run Django server on http://127.0.0.1:8000/ before continuing")
|
||||
sys.exit(0)
|
||||
|
||||
input("Welcome to SkoolOS. Press any key to create an account")
|
||||
#webbrowser.open("http://127.0.0.1:8000/login", new=2)
|
||||
# webbrowser.open("http://127.0.0.1:8000/login", new=2)
|
||||
authenticate()
|
||||
else:
|
||||
profiles = os.listdir()
|
||||
|
@ -55,98 +60,150 @@ def main():
|
|||
count = 1
|
||||
for i in range(len(profiles)):
|
||||
p = profiles[i]
|
||||
if('profile' in p):
|
||||
f = open(p,'r')
|
||||
if 'profile' in p:
|
||||
f = open(p, 'r')
|
||||
d = json.loads(f.read())
|
||||
f.close()
|
||||
info.append(d)
|
||||
users.append(str(count) + ") " + d['username'])
|
||||
count = count+1
|
||||
count = count + 1
|
||||
users.append(str(count) + ") Make new user")
|
||||
user = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'user',
|
||||
'choices':users,
|
||||
'message': 'Select User: ',
|
||||
},
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'user',
|
||||
'choices': users,
|
||||
'message': 'Select User: ',
|
||||
},
|
||||
]
|
||||
u = int(prompt(user)['user'].split(")")[0]) -1
|
||||
if(u+1 == count):
|
||||
u = int(prompt(user)['user'].split(")")[0]) - 1
|
||||
if u + 1 == count:
|
||||
authenticate()
|
||||
return
|
||||
data = info[u]
|
||||
PWD = data['password']
|
||||
USER = data['username']
|
||||
print(data['username'])
|
||||
if(data['is_student']):
|
||||
if data['is_student']:
|
||||
studentCLI(USER, PWD)
|
||||
else:
|
||||
teacherCLI(USER, PWD)
|
||||
|
||||
|
||||
|
||||
#################################################################################################### STUDENT METHODS
|
||||
|
||||
def studentCLI(user, password):
|
||||
"""
|
||||
The CLI for students to access
|
||||
:param user: student username
|
||||
:param password: student password
|
||||
"""
|
||||
from CLI import student
|
||||
data = getUser(user, password, 'student')
|
||||
student = student.Student(data, password)
|
||||
student.update()
|
||||
EXIT = False
|
||||
while(not EXIT):
|
||||
while not EXIT:
|
||||
course = chooseClassStudent(student)
|
||||
if(course == "Exit SkoolOS"):
|
||||
if course == "Exit SkoolOS":
|
||||
return
|
||||
EXIT = classOptionsStudent(student, course)
|
||||
|
||||
#return class
|
||||
def chooseClassStudent(student):
|
||||
|
||||
# return class
|
||||
def chooseClassStudent(student):
|
||||
"""
|
||||
Chooses a class for a student to view and work on
|
||||
:param student: a student
|
||||
:return: a course prompt
|
||||
"""
|
||||
carray = student.sclass.split(",")
|
||||
if(len(carray) == 1 and carray[0] == ""):
|
||||
if len(carray) == 1 and carray[0] == "":
|
||||
carray.remove("")
|
||||
print("No classes")
|
||||
|
||||
|
||||
carray.append("Exit SkoolOS")
|
||||
courses = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'course',
|
||||
'choices':carray,
|
||||
'message': 'Select class: ',
|
||||
},
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'course',
|
||||
'choices': carray,
|
||||
'message': 'Select class: ',
|
||||
},
|
||||
]
|
||||
course = prompt(courses)['course']
|
||||
print(course)
|
||||
return course
|
||||
|
||||
|
||||
def classOptionsStudent(student, course):
|
||||
"""
|
||||
Allows students to choose what they want to do related to a class
|
||||
The student can save, exit, or go back
|
||||
:param student: a student
|
||||
:param course: a course
|
||||
:return: True if exiting, False if going back
|
||||
"""
|
||||
student.viewClass(course)
|
||||
student.getAssignments(course, 100)
|
||||
choices = ["Save","Back","Exit SkoolOS"]
|
||||
choices = ["Save","Submit assignment","Back","Exit SkoolOS"]
|
||||
options = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'option',
|
||||
'choices':choices,
|
||||
'message': 'Select: ',
|
||||
},
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'option',
|
||||
'choices': choices,
|
||||
'message': 'Select: ',
|
||||
},
|
||||
]
|
||||
option = prompt(options)['option']
|
||||
if(option == "Save"):
|
||||
if option == "Save":
|
||||
student.update()
|
||||
print("Saved!")
|
||||
classOptionsStudent(student, course)
|
||||
if(option == "Back"):
|
||||
if option == "Back":
|
||||
student.exitCLI()
|
||||
#dont exit cli
|
||||
# dont exit cli
|
||||
return False
|
||||
if(option == "Exit SkoolOS"):
|
||||
if option == "Exit SkoolOS":
|
||||
student.exitCLI()
|
||||
#exit cli
|
||||
# exit cli
|
||||
return True
|
||||
if(option == "Submit assignment"):
|
||||
assignments = os.listdir(student.username)
|
||||
tlist = []
|
||||
b = True
|
||||
for a in assignments:
|
||||
oname = a + "_" + course
|
||||
a = student.username + "/" + a
|
||||
if(os.path.isdir(a) and not "." in a and not oname in student.completed):
|
||||
tlist.append(a)
|
||||
assignments = tlist
|
||||
assignments.append("Back")
|
||||
print(assignments)
|
||||
|
||||
options = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'submit',
|
||||
'choices':assignments,
|
||||
'message': 'Select: ',
|
||||
},
|
||||
]
|
||||
ass = prompt(options)['submit']
|
||||
if(ass == "Back"):
|
||||
return False
|
||||
else:
|
||||
student.submit(course, ass)
|
||||
return False
|
||||
|
||||
|
||||
|
||||
#################################################################################################### 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)
|
||||
|
@ -157,25 +214,28 @@ 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):
|
||||
#Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"
|
||||
while not EXIT:
|
||||
# Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"
|
||||
course = chooseGeneralTeacher(teacher)
|
||||
if course == "Exit SkoolOS":
|
||||
EXIT = True
|
||||
elif course == "Make New Class":
|
||||
EXIT = makeClassTeacher(teacher)
|
||||
#selected a class
|
||||
# selected a class
|
||||
else:
|
||||
#Pull confirmed students directory
|
||||
teacher.getStudents(course)
|
||||
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:
|
||||
|
@ -183,56 +243,57 @@ def chooseGeneralTeacher(teacher):
|
|||
carray.append("Make New Class")
|
||||
carray.append("Exit SkoolOS")
|
||||
courses = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'course',
|
||||
'choices':carray,
|
||||
'message': 'Select class: ',
|
||||
},
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'course',
|
||||
'choices': carray,
|
||||
'message': 'Select class: ',
|
||||
},
|
||||
]
|
||||
course = prompt(courses)['course']
|
||||
return course
|
||||
|
||||
|
||||
def makeClassTeacher(teacher):
|
||||
questions = [
|
||||
{
|
||||
'type': 'input',
|
||||
'name': 'cname',
|
||||
'message': 'Class Name (Must be: <subject>_<ion_user>): ',
|
||||
},
|
||||
]
|
||||
cname = prompt(questions)['cname']
|
||||
print(cname)
|
||||
while(not ("_" + teacher.username) in cname):
|
||||
print("Incorrect naming format")
|
||||
questions = [
|
||||
{
|
||||
'type': 'input',
|
||||
'name': 'cname',
|
||||
'message': 'Class Name (Must be: <subject>_<ion_user>): ',
|
||||
},
|
||||
]
|
||||
cname = prompt(questions)['cname']
|
||||
print(cname)
|
||||
while not ("_" + teacher.username) in cname:
|
||||
print("Incorrect naming format")
|
||||
questions = [
|
||||
{
|
||||
'type': 'input',
|
||||
'name': 'cname',
|
||||
'message': 'Class Name (Must be: <subject>_<ion_user>): ',
|
||||
},
|
||||
]
|
||||
cname = prompt(questions)['cname']
|
||||
|
||||
teacher.makeClass(cname)
|
||||
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
||||
questions = [
|
||||
{
|
||||
'type': 'list',
|
||||
'choices':soption,
|
||||
'name': 'students',
|
||||
'message': 'Add Students): ',
|
||||
},
|
||||
{
|
||||
'type': 'list',
|
||||
'choices': soption,
|
||||
'name': 'students',
|
||||
'message': 'Add Students): ',
|
||||
},
|
||||
]
|
||||
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): ")
|
||||
|
@ -241,6 +302,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']
|
||||
|
@ -248,49 +310,50 @@ def classOptionsTeacher(teacher, course):
|
|||
teacher.addStudent(s, course)
|
||||
options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"]
|
||||
questions = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'course',
|
||||
'choices':options,
|
||||
'message': 'Select option: ',
|
||||
},
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'course',
|
||||
'choices': options,
|
||||
'message': 'Select option: ',
|
||||
},
|
||||
]
|
||||
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 = [
|
||||
{
|
||||
'type': 'list',
|
||||
'choices':soption,
|
||||
'name': 'students',
|
||||
'message': 'Add list of students (input path): ',
|
||||
},
|
||||
{
|
||||
'type': 'list',
|
||||
'choices': soption,
|
||||
'name': 'students',
|
||||
'message': 'Add list of students (input path): ',
|
||||
},
|
||||
]
|
||||
schoice = prompt(questions)['students'].split(")")[0]
|
||||
if(schoice == '1'):
|
||||
if schoice == '1':
|
||||
questions = [
|
||||
{
|
||||
'type': 'input',
|
||||
'name': 'student',
|
||||
'message': 'Student Name: ',
|
||||
},
|
||||
{
|
||||
'type': 'input',
|
||||
'name': 'student',
|
||||
'message': 'Student Name: ',
|
||||
},
|
||||
]
|
||||
s = prompt(questions)['student']
|
||||
teacher.reqStudent(s, course)
|
||||
return False
|
||||
if(schoice == '2'):
|
||||
if schoice == '2':
|
||||
questions = [
|
||||
{
|
||||
'type': 'input',
|
||||
'name': 'path',
|
||||
'message': 'Path: ',
|
||||
},
|
||||
{
|
||||
'type': 'input',
|
||||
'name': 'path',
|
||||
'message': 'Path: ',
|
||||
},
|
||||
]
|
||||
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): ")
|
||||
|
@ -301,6 +364,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']
|
||||
|
@ -310,36 +374,36 @@ def addAssignmentTeacher(teacher, course):
|
|||
for n in nlist:
|
||||
b = True
|
||||
print(teacher.username + "/" + course + "/" + n)
|
||||
for a in alist:
|
||||
if(n in a or n == a):
|
||||
#print("Assignments: " + n)
|
||||
for a in alist:
|
||||
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 = [
|
||||
{
|
||||
'type': 'list',
|
||||
'choices':nlist,
|
||||
'name': 'assignment',
|
||||
'message': 'Select new assignment: ',
|
||||
},
|
||||
{
|
||||
'type': 'list',
|
||||
'choices': nlist,
|
||||
'name': 'assignment',
|
||||
'message': 'Select new assignment: ',
|
||||
},
|
||||
]
|
||||
ass = prompt(questions)['assignment']
|
||||
apath = teacher.username + "/" + course + "/" + ass
|
||||
due = input("Enter due date (Example: 2020-08-11 16:58): ")
|
||||
due = due + ":33.383124"
|
||||
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
|
||||
|
@ -347,10 +411,11 @@ def addAssignmentTeacher(teacher, course):
|
|||
print("Due-date format is incorrect.")
|
||||
print(due)
|
||||
due = input("Enter due date (Example: 2020-08-11 16:58): ")
|
||||
due = due + ":33.383124"
|
||||
due = due + ":33.383124"
|
||||
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"]
|
||||
|
@ -362,101 +427,176 @@ 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'])) and (not student in str(data['unconfirmed']))):
|
||||
print("Student not affiliated with class")
|
||||
student = input("View student ('N' to exit): ")
|
||||
if student == 'N':
|
||||
return True
|
||||
print(getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/"))
|
||||
|
||||
return False
|
||||
sinfo = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/")
|
||||
pprint.pprint(sinfo)
|
||||
print("Confirmed: " + str(student in str(data['confirmed'])))
|
||||
if(student in str(data['confirmed'])):
|
||||
path = teacher.username + "/Students/" + course + "/" + student
|
||||
print(student + "'s work: " + path)
|
||||
fin = sinfo['completed'].split(",")
|
||||
alist = []
|
||||
for f in fin:
|
||||
if(course in f):
|
||||
late = teacher.afterSubmit(course, f, student)
|
||||
if(late):
|
||||
s = f.split("_")[0] + " (LATE)"
|
||||
else:
|
||||
s = f.split("_")[0]
|
||||
alist.append(s)
|
||||
print("Has submitted: " + str(alist))
|
||||
|
||||
#put log stuff
|
||||
|
||||
############################################################################################################################################
|
||||
|
||||
|
||||
def getUser(ion_user, password, utype):
|
||||
if('student' in utype):
|
||||
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
||||
else:
|
||||
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
||||
"""
|
||||
Returns user information
|
||||
:param ion_user: user
|
||||
:param password: user's password
|
||||
:param utype: type of user (student or teacher
|
||||
:return: api user information
|
||||
"""
|
||||
if 'student' in utype:
|
||||
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
||||
else:
|
||||
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
||||
print(URL)
|
||||
r = requests.get(url = URL, auth=(ion_user,password))
|
||||
print(r.json())
|
||||
if(r.status_code == 200):
|
||||
data = r.json()
|
||||
print(200)
|
||||
return data
|
||||
elif(r.status_code == 404):
|
||||
print("Make new account!")
|
||||
return None
|
||||
elif(r.status_code == 403):
|
||||
print("Invalid username/password")
|
||||
return None
|
||||
else:
|
||||
print(r.status_code)
|
||||
return None
|
||||
r = requests.get(url=URL, auth=(ion_user, password))
|
||||
print(r.json())
|
||||
if r.status_code == 200:
|
||||
data = r.json()
|
||||
print(200)
|
||||
return data
|
||||
elif r.status_code == 404:
|
||||
print("Make new account!")
|
||||
return None
|
||||
elif r.status_code == 403:
|
||||
print("Invalid username/password")
|
||||
return None
|
||||
else:
|
||||
print(r.status_code)
|
||||
return None
|
||||
|
||||
|
||||
def patchDB(USER, PWD, url, data):
|
||||
r = requests.patch(url = url, data=data, auth=(USER,PWD))
|
||||
"""
|
||||
Sends a PATCH request to url
|
||||
:param USER: username
|
||||
:param PWD: password
|
||||
:param url: URL for request
|
||||
:param data: data to request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.patch(url=url, data=data, auth=(USER, PWD))
|
||||
print("PATH:" + str(r.status_code))
|
||||
return(r.json())
|
||||
return r.json()
|
||||
|
||||
|
||||
def getDB(USER, PWD, url):
|
||||
r = requests.get(url = url, auth=(USER,PWD))
|
||||
"""
|
||||
Sends a GET request to url
|
||||
:param USER: username
|
||||
:param PWD: password
|
||||
:param url: URL for request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.get(url=url, auth=(USER, PWD))
|
||||
print("GET:" + str(r.status_code))
|
||||
return(r.json())
|
||||
return r.json()
|
||||
|
||||
|
||||
def postDB(USER, PWD, url, data):
|
||||
r = requests.post(url = url, data=data, auth=(USER,PWD))
|
||||
"""
|
||||
Sends a POST request to url
|
||||
:param USER: username
|
||||
:param PWD: password
|
||||
:param url: URL for request
|
||||
:param data: data to request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.post(url=url, data=data, auth=(USER, PWD))
|
||||
print("POST:" + str(r.status_code))
|
||||
return(r.json())
|
||||
return r.json()
|
||||
|
||||
|
||||
def putDB(USER, PWD, url, data):
|
||||
r = requests.put(url = url, data=data, auth=(USER,PWD))
|
||||
"""
|
||||
Sends a PUT request to url
|
||||
:param USER: username
|
||||
:param PWD: password
|
||||
:param url: URL for request
|
||||
:param data: data to request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.put(url=url, data=data, auth=(USER, PWD))
|
||||
print("PUT:" + str(r.status_code))
|
||||
return(r.json())
|
||||
return r.json()
|
||||
|
||||
|
||||
def delDB(USER, PWD, url):
|
||||
r = requests.delete(url = url, auth=(USER,PWD))
|
||||
"""
|
||||
Sends a DELETE request to url
|
||||
:param USER: username
|
||||
:param PWD: password
|
||||
:param url: URL for request
|
||||
:return: json request response
|
||||
"""
|
||||
r = requests.delete(url=url, auth=(USER, PWD))
|
||||
print("DELETE:" + str(r.status_code))
|
||||
return None
|
||||
|
||||
|
||||
def makePass():
|
||||
"""
|
||||
Prompts the user to create a password
|
||||
:return: the password
|
||||
"""
|
||||
questions = [
|
||||
{
|
||||
'type': 'password',
|
||||
'name': 'pwd',
|
||||
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
||||
},
|
||||
{
|
||||
'type': 'password',
|
||||
'name': 'pwd',
|
||||
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
||||
},
|
||||
]
|
||||
pwd = prompt(questions)['pwd']
|
||||
while(len(pwd) < 7):
|
||||
while len(pwd) < 7:
|
||||
print("Password too short (Must be over 6 characters)")
|
||||
pwd = prompt(questions)['pwd']
|
||||
conf = [
|
||||
{
|
||||
'type': 'password',
|
||||
'name': 'pwd',
|
||||
'message': 'Re-enter password: ',
|
||||
},
|
||||
{
|
||||
'type': 'password',
|
||||
'name': 'pwd',
|
||||
'message': 'Re-enter password: ',
|
||||
},
|
||||
]
|
||||
pwd2 = prompt(conf)['pwd']
|
||||
while(not pwd == pwd2):
|
||||
while not pwd == pwd2:
|
||||
print("Passwords do not match.")
|
||||
pwd2 = prompt(conf)['pwd']
|
||||
else:
|
||||
print("PASSWORD SAVED")
|
||||
return pwd
|
||||
|
||||
|
||||
def authenticate():
|
||||
"""
|
||||
Authenticates the user via Ion OAuth
|
||||
"""
|
||||
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
|
||||
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
|
||||
|
||||
cdir = os.getcwd()
|
||||
#Linux: chromdriver-linux
|
||||
#Macos: chromdriver-mac
|
||||
#Windows: chromdriver.exe
|
||||
path = os.path.join(os.getcwd(),'chromedriver','chromedriver-linux')
|
||||
# Linux: chromdriver-linux
|
||||
# Macos: chromdriver-mac
|
||||
# Windows: chromdriver.exe
|
||||
path = os.path.join(os.getcwd(), 'chromedriver', 'chromedriver-mac')
|
||||
|
||||
browser = webdriver.Chrome(path)
|
||||
|
||||
|
@ -467,7 +607,8 @@ def authenticate():
|
|||
|
||||
url = browser.current_url
|
||||
gets = url_decode(url.replace("http://localhost:8000/login/?", ""))
|
||||
while "http://localhost:8000/login/?username=" not in browser.current_url and (not browser.current_url == "http://localhost:8000/"): #http://localhost:8000/
|
||||
while "http://localhost:8000/login/?username=" not in browser.current_url and (
|
||||
not browser.current_url == "http://localhost:8000/"): # http://localhost:8000/
|
||||
time.sleep(0.25)
|
||||
|
||||
url = browser.current_url
|
||||
|
@ -478,42 +619,42 @@ def authenticate():
|
|||
# print("states good")
|
||||
browser.quit()
|
||||
questions = [
|
||||
{
|
||||
'type': 'input',
|
||||
'name': 'username',
|
||||
'message': 'Enter SkoolOS Username (Same as ION Username): ',
|
||||
},
|
||||
{
|
||||
'type': 'password',
|
||||
'name': 'pwd',
|
||||
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
||||
},
|
||||
{
|
||||
'type': 'input',
|
||||
'name': 'username',
|
||||
'message': 'Enter SkoolOS Username (Same as ION Username): ',
|
||||
},
|
||||
{
|
||||
'type': 'password',
|
||||
'name': 'pwd',
|
||||
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
||||
},
|
||||
]
|
||||
data =prompt(questions)
|
||||
data = prompt(questions)
|
||||
pwd = data['pwd']
|
||||
user = data['username']
|
||||
r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd))
|
||||
while(r.status_code != 200):
|
||||
r = requests.get(url="http://localhost:8000/api/", auth=(user, pwd))
|
||||
while r.status_code != 200:
|
||||
print("INCORRECT LOGIN CREDENTIALS")
|
||||
r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd))
|
||||
data =prompt(questions)
|
||||
r = requests.get(url="http://localhost:8000/api/", auth=(user, pwd))
|
||||
data = prompt(questions)
|
||||
pwd = data['pwd']
|
||||
user = data['username']
|
||||
print(r.status_code)
|
||||
r = requests.get(url = "http://localhost:8000/api/students/" + user + "/", auth=(user,pwd))
|
||||
r = requests.get(url="http://localhost:8000/api/students/" + user + "/", auth=(user, pwd))
|
||||
is_student = False
|
||||
if(r.status_code == 200):
|
||||
if r.status_code == 200:
|
||||
is_student = True
|
||||
print("Welcome, student " + user)
|
||||
r = requests.get(url = "http://localhost:8000/api/students/" + user + "/", auth=(user,pwd))
|
||||
r = requests.get(url="http://localhost:8000/api/students/" + user + "/", auth=(user, pwd))
|
||||
profile = r.json()
|
||||
username = profile['ion_user']
|
||||
grade = profile['grade']
|
||||
profile = {
|
||||
'username':username,
|
||||
'grade':grade,
|
||||
'is_student':is_student,
|
||||
'password':pwd,
|
||||
'username': username,
|
||||
'grade': grade,
|
||||
'is_student': is_student,
|
||||
'password': pwd,
|
||||
}
|
||||
fname = "." + username + "profile"
|
||||
profileFile = open(fname, "w")
|
||||
|
@ -522,13 +663,13 @@ def authenticate():
|
|||
|
||||
else:
|
||||
print("Welcome, teacher " + user)
|
||||
r = requests.get(url = "http://localhost:8000/api/teachers/" + user + "/", auth=(user,pwd))
|
||||
r = requests.get(url="http://localhost:8000/api/teachers/" + user + "/", auth=(user, pwd))
|
||||
profile = r.json()
|
||||
username = profile['ion_user']
|
||||
profile = {
|
||||
'username':username,
|
||||
'is_student':is_student,
|
||||
'password':pwd,
|
||||
'username': username,
|
||||
'is_student': is_student,
|
||||
'password': pwd,
|
||||
}
|
||||
fname = "." + username + "profile"
|
||||
profileFile = open(fname, "w")
|
||||
|
@ -539,11 +680,15 @@ def authenticate():
|
|||
|
||||
|
||||
def create_server():
|
||||
"""
|
||||
Creates a simple HTTP server for creating api requests from the CLI
|
||||
"""
|
||||
port = 8000
|
||||
handler = http.server.SimpleHTTPRequestHandler
|
||||
httpd = socketserver.TCPServer(("", port), handler)
|
||||
print("serving at port:" + str(port))
|
||||
httpd.serve_forever()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user