mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-19 03:40:17 -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
|
#makes a GET request to given url, returns dict
|
||||||
def getDB(user, pwd, url):
|
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
|
:param url: URL for request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.get(url=url, auth=(user, pwd))
|
r = requests.get(url=url, auth=(user, pwd))
|
||||||
print("GET:" + str(r.status_code))
|
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
|
#makes a PATCH (updates instance) request to given url, returns dict
|
||||||
def patchDB(user, pwd, data, url):
|
def patchDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PATCH request to the URL
|
Sends a PATCH request to url
|
||||||
:param data:
|
:param user: username
|
||||||
|
:param pwd: password
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
|
:param data: data to request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.patch(url=url, data=data, auth=(user, pwd))
|
r = requests.patch(url=url, data=data, auth=(user, pwd))
|
||||||
print("PATCH:" + str(r.status_code))
|
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
|
#makes a POST (makes new instance) request to given url, returns dict
|
||||||
def postDB(user, pwd, data, url):
|
def postDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a POST request to the URL
|
Sends a POST request to url
|
||||||
:param data:
|
:param user: username
|
||||||
|
:param pwd: password
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
|
:param data: data to request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.post(url=url, data=data, auth=(user, pwd))
|
r = requests.post(url=url, data=data, auth=(user, pwd))
|
||||||
print("POST:" + str(r.status_code))
|
print("POST:" + str(r.status_code))
|
||||||
|
@ -66,9 +75,12 @@ def postDB(user, pwd, data, url):
|
||||||
#makes a PUT (overwrites instance) request to given url, returns dict
|
#makes a PUT (overwrites instance) request to given url, returns dict
|
||||||
def putDB(user, pwd, data, url):
|
def putDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PUT request to the URL
|
Sends a PUT request to url
|
||||||
:param data:
|
:param user: username
|
||||||
|
:param pwd: password
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
|
:param data: data to request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.put(url=url, data=data, auth=(user, pwd))
|
r = requests.put(url=url, data=data, auth=(user, pwd))
|
||||||
print("PUT:" + str(r.status_code))
|
print("PUT:" + str(r.status_code))
|
||||||
|
@ -78,8 +90,11 @@ def putDB(user, pwd, data, url):
|
||||||
#makes a DELETE (delete instance) request to given url, returns dict
|
#makes a DELETE (delete instance) request to given url, returns dict
|
||||||
def delDB(user, pwd, url):
|
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
|
:param url: URL for request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.delete(url=url, auth=(user, pwd))
|
r = requests.delete(url=url, auth=(user, pwd))
|
||||||
print("DELETE:" + str(r.status_code))
|
print("DELETE:" + str(r.status_code))
|
||||||
|
@ -112,6 +127,7 @@ class Student:
|
||||||
self.completed = data['completed']
|
self.completed = data['completed']
|
||||||
self.user = data['user']
|
self.user = data['user']
|
||||||
self.password = password
|
self.password = password
|
||||||
|
self.completed = data['completed']
|
||||||
# classes in id form (Example: 4,5)
|
# classes in id form (Example: 4,5)
|
||||||
# storing actual classes
|
# storing actual classes
|
||||||
cid = data['classes'].split(",")
|
cid = data['classes'].split(",")
|
||||||
|
@ -385,12 +401,13 @@ class Student:
|
||||||
command("git add .")
|
command("git add .")
|
||||||
command("git commit -m update")
|
command("git commit -m update")
|
||||||
command('git checkout ' + course)
|
command('git checkout ' + course)
|
||||||
time.sleep(5)
|
|
||||||
ass = os.listdir()
|
ass = os.listdir()
|
||||||
|
oname = ''
|
||||||
inclass = False
|
inclass = False
|
||||||
for a in ass:
|
for a in ass:
|
||||||
if a == assignment:
|
if a in assignment:
|
||||||
inclass = True
|
inclass = True
|
||||||
|
oname = a + "_" + course
|
||||||
break
|
break
|
||||||
if (inclass == False):
|
if (inclass == False):
|
||||||
print(assignment + " not an assignment of " + course)
|
print(assignment + " not an assignment of " + course)
|
||||||
|
@ -404,6 +421,11 @@ class Student:
|
||||||
command("git tag " + assignment + "-final")
|
command("git tag " + assignment + "-final")
|
||||||
command("git push -u origin " + course + " --tags")
|
command("git push -u origin " + course + " --tags")
|
||||||
command('git checkout master')
|
command('git checkout master')
|
||||||
|
self.completed = assignment + "," + self.completed
|
||||||
|
data = {
|
||||||
|
'completed': self.completed
|
||||||
|
}
|
||||||
|
patchDB(self.username, self.password, data, self.url)
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ def getTeacher(ion_user, password):
|
||||||
"""
|
"""
|
||||||
Gets information about a teacher from the api
|
Gets information about a teacher from the api
|
||||||
:param ion_user: a teacher
|
:param ion_user: a teacher
|
||||||
:param password: a string
|
:param password: the teacher's password
|
||||||
:return: teacher information or error
|
:return: teacher information or error
|
||||||
"""
|
"""
|
||||||
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
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
|
#makes a GET request to given url, returns dict
|
||||||
def getDB(user, pwd, url):
|
def getDB(user, pwd, url):
|
||||||
"""
|
"""
|
||||||
Sends a GET request to the URL
|
Sends a GET request to url
|
||||||
:param user: a string
|
:param user: username
|
||||||
:param password: a string
|
:param pwd: password
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.get(url=url, auth=(user, pwd))
|
r = requests.get(url=url, auth=(user, pwd))
|
||||||
print("GET:" + str(r.status_code))
|
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
|
#makes a PATCH (updates instance) request to given url, returns dict
|
||||||
def patchDB(user, pwd, data, url):
|
def patchDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PATCH request to the URL
|
Sends a PATCH request to url
|
||||||
:param data:
|
:param user: username
|
||||||
:param user: a string
|
:param pwd: password
|
||||||
:param password: a string
|
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
|
:param data: data to request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.patch(url=url, data=data, auth=(user, pwd))
|
r = requests.patch(url=url, data=data, auth=(user, pwd))
|
||||||
print("PATCH:" + str(r.status_code))
|
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
|
#makes a POST (makes new instance) request to given url, returns dict
|
||||||
def postDB(user, pwd, data, url):
|
def postDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a POST request to the URL
|
Sends a POST request to url
|
||||||
:param data:
|
:param user: username
|
||||||
:param user: a string
|
:param pwd: password
|
||||||
:param password: a string
|
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
|
:param data: data to request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.post(url=url, data=data, auth=(user, pwd))
|
r = requests.post(url=url, data=data, auth=(user, pwd))
|
||||||
print("POST:" + str(r.status_code))
|
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
|
#makes a PUT (overwrites instance) request to given url, returns dict
|
||||||
def putDB(user, pwd, data, url):
|
def putDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PUT request to the URL
|
Sends a PUT request to url
|
||||||
:param user: a string
|
:param user: username
|
||||||
:param password: a string
|
:param pwd: password
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
|
:param data: data to request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.put(url=url, data=data, auth=(user, pwd))
|
r = requests.put(url=url, data=data, auth=(user, pwd))
|
||||||
print("PUT:" + str(r.status_code))
|
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
|
#makes a DELETE (delete instance) request to given url, returns dict
|
||||||
def delDB(user, pwd, url):
|
def delDB(user, pwd, url):
|
||||||
"""
|
"""
|
||||||
Sends a DELETE request to the URL
|
Sends a DELETE request to url
|
||||||
:param user: a string
|
:param user: username
|
||||||
:param password: a string
|
:param pwd: password
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
|
:return: json request response
|
||||||
"""
|
"""
|
||||||
r = requests.delete(url=url, auth=(user, pwd))
|
r = requests.delete(url=url, auth=(user, pwd))
|
||||||
print("DELETE:" + str(r.status_code))
|
print("DELETE:" + str(r.status_code))
|
||||||
|
@ -152,6 +158,13 @@ class Teacher:
|
||||||
self.classes = data['classes']
|
self.classes = data['classes']
|
||||||
if os.path.isdir(self.username + "/Students"):
|
if os.path.isdir(self.username + "/Students"):
|
||||||
print("Synced to " + self.username)
|
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:
|
else:
|
||||||
os.makedirs(self.username + "/Students")
|
os.makedirs(self.username + "/Students")
|
||||||
|
|
||||||
|
@ -604,7 +617,7 @@ class Teacher:
|
||||||
|
|
||||||
# pull student's work, no modifications
|
# pull student's work, no modifications
|
||||||
def getStudents(self, course):
|
def getStudents(self, course):
|
||||||
if not (course in self.sclass):
|
if not (course in str(self.classes)):
|
||||||
print(course + " not a class.")
|
print(course + " not a class.")
|
||||||
return
|
return
|
||||||
path = self.username + "/Students/" + course
|
path = self.username + "/Students/" + course
|
||||||
|
@ -697,7 +710,7 @@ class Teacher:
|
||||||
# 'classes':course
|
# 'classes':course
|
||||||
# }
|
# }
|
||||||
log = self.getCommits(student, course, 30)
|
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
|
late = False
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
os.chdir(self.username + "/Students/" + course + "/" + student)
|
os.chdir(self.username + "/Students/" + course + "/" + student)
|
||||||
|
@ -727,7 +740,7 @@ class Teacher:
|
||||||
|
|
||||||
# data = getTeacher("eharris1","PWD")
|
# data = getTeacher("eharris1","PWD")
|
||||||
# print(data)
|
# print(data)
|
||||||
# t = Teacher(data, "PWD")
|
#t = Teacher(data, "PWD")
|
||||||
# t.makeClass("APLit_eharris1")
|
# t.makeClass("APLit_eharris1")
|
||||||
# t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124')
|
# t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124')
|
||||||
# ar = ['2022rkhondak','2022inafi','2023rumareti']
|
# 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
325
skoolos.py
325
skoolos.py
|
@ -25,7 +25,12 @@ scope = ["read"]
|
||||||
USER = ""
|
USER = ""
|
||||||
PWD = ""
|
PWD = ""
|
||||||
|
|
||||||
|
|
||||||
def main():
|
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("░██████╗██╗░░██╗░█████╗░░█████╗░██╗░░░░░ ░█████╗░░██████╗")
|
print("░██████╗██╗░░██╗░█████╗░░█████╗░██╗░░░░░ ░█████╗░░██████╗")
|
||||||
print("██╔════╝██║░██╔╝██╔══██╗██╔══██╗██║░░░░░ ██╔══██╗██╔════╝")
|
print("██╔════╝██║░██╔╝██╔══██╗██╔══██╗██║░░░░░ ██╔══██╗██╔════╝")
|
||||||
|
@ -40,13 +45,13 @@ def main():
|
||||||
if not ("profile" in str(profiles)):
|
if not ("profile" in str(profiles)):
|
||||||
try:
|
try:
|
||||||
URL = "http://127.0.0.1:8000/api/"
|
URL = "http://127.0.0.1:8000/api/"
|
||||||
r = requests.get(url = URL)
|
r = requests.get(url=URL)
|
||||||
except:
|
except:
|
||||||
print("Run Django server on http://127.0.0.1:8000/ before continuing")
|
print("Run Django server on http://127.0.0.1:8000/ before continuing")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
input("Welcome to SkoolOS. Press any key to create an account")
|
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()
|
authenticate()
|
||||||
else:
|
else:
|
||||||
profiles = os.listdir()
|
profiles = os.listdir()
|
||||||
|
@ -55,53 +60,65 @@ def main():
|
||||||
count = 1
|
count = 1
|
||||||
for i in range(len(profiles)):
|
for i in range(len(profiles)):
|
||||||
p = profiles[i]
|
p = profiles[i]
|
||||||
if('profile' in p):
|
if 'profile' in p:
|
||||||
f = open(p,'r')
|
f = open(p, 'r')
|
||||||
d = json.loads(f.read())
|
d = json.loads(f.read())
|
||||||
f.close()
|
f.close()
|
||||||
info.append(d)
|
info.append(d)
|
||||||
users.append(str(count) + ") " + d['username'])
|
users.append(str(count) + ") " + d['username'])
|
||||||
count = count+1
|
count = count + 1
|
||||||
users.append(str(count) + ") Make new user")
|
users.append(str(count) + ") Make new user")
|
||||||
user = [
|
user = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'name': 'user',
|
'name': 'user',
|
||||||
'choices':users,
|
'choices': users,
|
||||||
'message': 'Select User: ',
|
'message': 'Select User: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
u = int(prompt(user)['user'].split(")")[0]) -1
|
u = int(prompt(user)['user'].split(")")[0]) - 1
|
||||||
if(u+1 == count):
|
if u + 1 == count:
|
||||||
authenticate()
|
authenticate()
|
||||||
return
|
return
|
||||||
data = info[u]
|
data = info[u]
|
||||||
PWD = data['password']
|
PWD = data['password']
|
||||||
USER = data['username']
|
USER = data['username']
|
||||||
print(data['username'])
|
print(data['username'])
|
||||||
if(data['is_student']):
|
if data['is_student']:
|
||||||
studentCLI(USER, PWD)
|
studentCLI(USER, PWD)
|
||||||
else:
|
else:
|
||||||
teacherCLI(USER, PWD)
|
teacherCLI(USER, PWD)
|
||||||
|
|
||||||
|
|
||||||
#################################################################################################### STUDENT METHODS
|
#################################################################################################### STUDENT METHODS
|
||||||
|
|
||||||
def studentCLI(user, password):
|
def studentCLI(user, password):
|
||||||
|
"""
|
||||||
|
The CLI for students to access
|
||||||
|
:param user: student username
|
||||||
|
:param password: student password
|
||||||
|
"""
|
||||||
from CLI import student
|
from CLI import student
|
||||||
data = getUser(user, password, 'student')
|
data = getUser(user, password, 'student')
|
||||||
student = student.Student(data, password)
|
student = student.Student(data, password)
|
||||||
student.update()
|
student.update()
|
||||||
EXIT = False
|
EXIT = False
|
||||||
while(not EXIT):
|
while not EXIT:
|
||||||
course = chooseClassStudent(student)
|
course = chooseClassStudent(student)
|
||||||
if(course == "Exit SkoolOS"):
|
if course == "Exit SkoolOS":
|
||||||
return
|
return
|
||||||
EXIT = classOptionsStudent(student, course)
|
EXIT = classOptionsStudent(student, course)
|
||||||
|
|
||||||
#return class
|
|
||||||
|
# return class
|
||||||
def chooseClassStudent(student):
|
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(",")
|
carray = student.sclass.split(",")
|
||||||
if(len(carray) == 1 and carray[0] == ""):
|
if len(carray) == 1 and carray[0] == "":
|
||||||
carray.remove("")
|
carray.remove("")
|
||||||
print("No classes")
|
print("No classes")
|
||||||
|
|
||||||
|
@ -110,7 +127,7 @@ def chooseClassStudent(student):
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'name': 'course',
|
'name': 'course',
|
||||||
'choices':carray,
|
'choices': carray,
|
||||||
'message': 'Select class: ',
|
'message': 'Select class: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -118,35 +135,75 @@ def chooseClassStudent(student):
|
||||||
print(course)
|
print(course)
|
||||||
return course
|
return course
|
||||||
|
|
||||||
|
|
||||||
def classOptionsStudent(student, 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.viewClass(course)
|
||||||
student.getAssignments(course, 100)
|
student.getAssignments(course, 100)
|
||||||
choices = ["Save","Back","Exit SkoolOS"]
|
choices = ["Save","Submit assignment","Back","Exit SkoolOS"]
|
||||||
options = [
|
options = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'name': 'option',
|
'name': 'option',
|
||||||
'choices':choices,
|
'choices': choices,
|
||||||
'message': 'Select: ',
|
'message': 'Select: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
option = prompt(options)['option']
|
option = prompt(options)['option']
|
||||||
if(option == "Save"):
|
if option == "Save":
|
||||||
student.update()
|
student.update()
|
||||||
print("Saved!")
|
print("Saved!")
|
||||||
classOptionsStudent(student, course)
|
classOptionsStudent(student, course)
|
||||||
if(option == "Back"):
|
if option == "Back":
|
||||||
student.exitCLI()
|
student.exitCLI()
|
||||||
#dont exit cli
|
# dont exit cli
|
||||||
return False
|
return False
|
||||||
if(option == "Exit SkoolOS"):
|
if option == "Exit SkoolOS":
|
||||||
student.exitCLI()
|
student.exitCLI()
|
||||||
#exit cli
|
# exit cli
|
||||||
return True
|
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
|
#################################################################################################### TEACHER METHODS
|
||||||
def teacherCLI(user, password):
|
def teacherCLI(user, password):
|
||||||
|
"""
|
||||||
|
The CLI for teachers to access
|
||||||
|
:param user: teachers username
|
||||||
|
:param password: teachers password
|
||||||
|
"""
|
||||||
from CLI import teacher
|
from CLI import teacher
|
||||||
data = getUser(user, password, 'teacher')
|
data = getUser(user, password, 'teacher')
|
||||||
print(data)
|
print(data)
|
||||||
|
@ -157,25 +214,28 @@ def teacherCLI(user, password):
|
||||||
# 3. Get progress logs on a student
|
# 3. Get progress logs on a student
|
||||||
# 2. make an assignment for a class
|
# 2. make an assignment for a class
|
||||||
# 3. view student submissions for an assignment
|
# 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"
|
# Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"
|
||||||
course = chooseGeneralTeacher(teacher)
|
course = chooseGeneralTeacher(teacher)
|
||||||
if course == "Exit SkoolOS":
|
if course == "Exit SkoolOS":
|
||||||
EXIT = True
|
EXIT = True
|
||||||
elif course == "Make New Class":
|
elif course == "Make New Class":
|
||||||
EXIT = makeClassTeacher(teacher)
|
EXIT = makeClassTeacher(teacher)
|
||||||
#selected a class
|
# selected a class
|
||||||
else:
|
else:
|
||||||
|
#Pull confirmed students directory
|
||||||
|
teacher.getStudents(course)
|
||||||
option = classOptionsTeacher(teacher, course)
|
option = classOptionsTeacher(teacher, course)
|
||||||
if(option == '1'):
|
if option == '1':
|
||||||
EXIT = addStudentsTeacher(teacher, course)
|
EXIT = addStudentsTeacher(teacher, course)
|
||||||
elif(option == '2'):
|
elif option == '2':
|
||||||
EXIT = addAssignmentTeacher(teacher, course)
|
EXIT = addAssignmentTeacher(teacher, course)
|
||||||
elif(option == '3'):
|
elif option == '3':
|
||||||
EXIT = viewStudentsTeacher(teacher, course)
|
EXIT = viewStudentsTeacher(teacher, course)
|
||||||
else:
|
else:
|
||||||
EXIT = True
|
EXIT = True
|
||||||
|
|
||||||
|
|
||||||
def chooseGeneralTeacher(teacher):
|
def chooseGeneralTeacher(teacher):
|
||||||
carray = []
|
carray = []
|
||||||
for c in teacher.classes:
|
for c in teacher.classes:
|
||||||
|
@ -186,13 +246,14 @@ def chooseGeneralTeacher(teacher):
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'name': 'course',
|
'name': 'course',
|
||||||
'choices':carray,
|
'choices': carray,
|
||||||
'message': 'Select class: ',
|
'message': 'Select class: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
course = prompt(courses)['course']
|
course = prompt(courses)['course']
|
||||||
return course
|
return course
|
||||||
|
|
||||||
|
|
||||||
def makeClassTeacher(teacher):
|
def makeClassTeacher(teacher):
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
|
@ -203,7 +264,7 @@ def makeClassTeacher(teacher):
|
||||||
]
|
]
|
||||||
cname = prompt(questions)['cname']
|
cname = prompt(questions)['cname']
|
||||||
print(cname)
|
print(cname)
|
||||||
while(not ("_" + teacher.username) in cname):
|
while not ("_" + teacher.username) in cname:
|
||||||
print("Incorrect naming format")
|
print("Incorrect naming format")
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
|
@ -219,20 +280,20 @@ def makeClassTeacher(teacher):
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'choices':soption,
|
'choices': soption,
|
||||||
'name': 'students',
|
'name': 'students',
|
||||||
'message': 'Add Students): ',
|
'message': 'Add Students): ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
choice = prompt(questions)['students'].split(")")[0]
|
choice = prompt(questions)['students'].split(")")[0]
|
||||||
if("1" == choice):
|
if "1" == choice:
|
||||||
s = input("Student name: ")
|
s = input("Student name: ")
|
||||||
teacher.addStudent(s, cname)
|
teacher.addStudent(s, cname)
|
||||||
if("2" == choice):
|
if "2" == choice:
|
||||||
print("File must be .txt and have 1 student username per line")
|
print("File must be .txt and have 1 student username per line")
|
||||||
path = input("Relative Path: ")
|
path = input("Relative Path: ")
|
||||||
while(not os.path.exists(path)):
|
while not os.path.exists(path):
|
||||||
if(path == 'N'):
|
if path == 'N':
|
||||||
return True
|
return True
|
||||||
print(path + " is not a valid path")
|
print(path + " is not a valid path")
|
||||||
path = input("Enter file path ('N' to exit): ")
|
path = input("Enter file path ('N' to exit): ")
|
||||||
|
@ -241,6 +302,7 @@ def makeClassTeacher(teacher):
|
||||||
teacher.reqAddStudentList(students, cname)
|
teacher.reqAddStudentList(students, cname)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def classOptionsTeacher(teacher, course):
|
def classOptionsTeacher(teacher, course):
|
||||||
print("Class: " + course)
|
print("Class: " + course)
|
||||||
unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed']
|
unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed']
|
||||||
|
@ -251,25 +313,26 @@ def classOptionsTeacher(teacher, course):
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'name': 'course',
|
'name': 'course',
|
||||||
'choices':options,
|
'choices': options,
|
||||||
'message': 'Select option: ',
|
'message': 'Select option: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
option = prompt(questions)['course'].split(")")[0]
|
option = prompt(questions)['course'].split(")")[0]
|
||||||
return option
|
return option
|
||||||
|
|
||||||
|
|
||||||
def addStudentsTeacher(teacher, course):
|
def addStudentsTeacher(teacher, course):
|
||||||
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'choices':soption,
|
'choices': soption,
|
||||||
'name': 'students',
|
'name': 'students',
|
||||||
'message': 'Add list of students (input path): ',
|
'message': 'Add list of students (input path): ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
schoice = prompt(questions)['students'].split(")")[0]
|
schoice = prompt(questions)['students'].split(")")[0]
|
||||||
if(schoice == '1'):
|
if schoice == '1':
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'input',
|
'type': 'input',
|
||||||
|
@ -280,7 +343,7 @@ def addStudentsTeacher(teacher, course):
|
||||||
s = prompt(questions)['student']
|
s = prompt(questions)['student']
|
||||||
teacher.reqStudent(s, course)
|
teacher.reqStudent(s, course)
|
||||||
return False
|
return False
|
||||||
if(schoice == '2'):
|
if schoice == '2':
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'input',
|
'type': 'input',
|
||||||
|
@ -289,8 +352,8 @@ def addStudentsTeacher(teacher, course):
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
path = prompt(questions)['path']
|
path = prompt(questions)['path']
|
||||||
while(not os.path.exists(path)):
|
while not os.path.exists(path):
|
||||||
if(path == 'N'):
|
if path == 'N':
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
print(path + " is not a valid path")
|
print(path + " is not a valid path")
|
||||||
path = input("Enter file path ('N' to exit): ")
|
path = input("Enter file path ('N' to exit): ")
|
||||||
|
@ -301,6 +364,7 @@ def addStudentsTeacher(teacher, course):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def addAssignmentTeacher(teacher, course):
|
def addAssignmentTeacher(teacher, course):
|
||||||
nlist = os.listdir(teacher.username + "/" + course)
|
nlist = os.listdir(teacher.username + "/" + course)
|
||||||
alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments']
|
alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments']
|
||||||
|
@ -311,24 +375,24 @@ def addAssignmentTeacher(teacher, course):
|
||||||
b = True
|
b = True
|
||||||
print(teacher.username + "/" + course + "/" + n)
|
print(teacher.username + "/" + course + "/" + n)
|
||||||
for a in alist:
|
for a in alist:
|
||||||
if(n in a or n == a):
|
if n in a or n == a:
|
||||||
#print("Assignments: " + n)
|
# print("Assignments: " + n)
|
||||||
b = False
|
b = False
|
||||||
if(not os.path.isdir(teacher.username + "/" + course + "/" + n)):
|
if not os.path.isdir(teacher.username + "/" + course + "/" + n):
|
||||||
b = False
|
b = False
|
||||||
if(b):
|
if b:
|
||||||
tlist.append(n)
|
tlist.append(n)
|
||||||
|
|
||||||
|
|
||||||
nlist = tlist
|
nlist = tlist
|
||||||
if(len(nlist) == 0):
|
if len(nlist) == 0:
|
||||||
print("No new assignments found")
|
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
|
return False
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'choices':nlist,
|
'choices': nlist,
|
||||||
'name': 'assignment',
|
'name': 'assignment',
|
||||||
'message': 'Select new assignment: ',
|
'message': 'Select new assignment: ',
|
||||||
},
|
},
|
||||||
|
@ -339,7 +403,7 @@ def addAssignmentTeacher(teacher, course):
|
||||||
due = due + ":33.383124"
|
due = due + ":33.383124"
|
||||||
due = due.strip()
|
due = due.strip()
|
||||||
f = False
|
f = False
|
||||||
while(not f):
|
while not f:
|
||||||
try:
|
try:
|
||||||
datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
||||||
f = True
|
f = True
|
||||||
|
@ -351,6 +415,7 @@ def addAssignmentTeacher(teacher, course):
|
||||||
teacher.addAssignment(apath, course, due)
|
teacher.addAssignment(apath, course, due)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def viewStudentsTeacher(teacher, course):
|
def viewStudentsTeacher(teacher, course):
|
||||||
data = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/classes/" + course)
|
data = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/classes/" + course)
|
||||||
students = data["confirmed"]
|
students = data["confirmed"]
|
||||||
|
@ -362,66 +427,137 @@ def viewStudentsTeacher(teacher, course):
|
||||||
for s in unconf:
|
for s in unconf:
|
||||||
print(s)
|
print(s)
|
||||||
student = input("View student (Enter student's ion username): ")
|
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")
|
print("Student not affiliated with class")
|
||||||
student = input("View student ('N' to exit): ")
|
student = input("View student ('N' to exit): ")
|
||||||
if student == 'N':
|
if student == 'N':
|
||||||
return True
|
return False
|
||||||
print(getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/"))
|
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):
|
def getUser(ion_user, password, utype):
|
||||||
if('student' in utype):
|
"""
|
||||||
|
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 + "/"
|
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
||||||
else:
|
else:
|
||||||
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
||||||
print(URL)
|
print(URL)
|
||||||
r = requests.get(url = URL, auth=(ion_user,password))
|
r = requests.get(url=URL, auth=(ion_user, password))
|
||||||
print(r.json())
|
print(r.json())
|
||||||
if(r.status_code == 200):
|
if r.status_code == 200:
|
||||||
data = r.json()
|
data = r.json()
|
||||||
print(200)
|
print(200)
|
||||||
return data
|
return data
|
||||||
elif(r.status_code == 404):
|
elif r.status_code == 404:
|
||||||
print("Make new account!")
|
print("Make new account!")
|
||||||
return None
|
return None
|
||||||
elif(r.status_code == 403):
|
elif r.status_code == 403:
|
||||||
print("Invalid username/password")
|
print("Invalid username/password")
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
print(r.status_code)
|
print(r.status_code)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def patchDB(USER, PWD, url, data):
|
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))
|
print("PATH:" + str(r.status_code))
|
||||||
return(r.json())
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def getDB(USER, PWD, url):
|
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))
|
print("GET:" + str(r.status_code))
|
||||||
return(r.json())
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def postDB(USER, PWD, url, data):
|
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))
|
print("POST:" + str(r.status_code))
|
||||||
return(r.json())
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def putDB(USER, PWD, url, data):
|
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))
|
print("PUT:" + str(r.status_code))
|
||||||
return(r.json())
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def delDB(USER, PWD, url):
|
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))
|
print("DELETE:" + str(r.status_code))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def makePass():
|
def makePass():
|
||||||
|
"""
|
||||||
|
Prompts the user to create a password
|
||||||
|
:return: the password
|
||||||
|
"""
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'password',
|
'type': 'password',
|
||||||
|
@ -430,7 +566,7 @@ def makePass():
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
pwd = prompt(questions)['pwd']
|
pwd = prompt(questions)['pwd']
|
||||||
while(len(pwd) < 7):
|
while len(pwd) < 7:
|
||||||
print("Password too short (Must be over 6 characters)")
|
print("Password too short (Must be over 6 characters)")
|
||||||
pwd = prompt(questions)['pwd']
|
pwd = prompt(questions)['pwd']
|
||||||
conf = [
|
conf = [
|
||||||
|
@ -441,22 +577,26 @@ def makePass():
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
pwd2 = prompt(conf)['pwd']
|
pwd2 = prompt(conf)['pwd']
|
||||||
while(not pwd == pwd2):
|
while not pwd == pwd2:
|
||||||
print("Passwords do not match.")
|
print("Passwords do not match.")
|
||||||
pwd2 = prompt(conf)['pwd']
|
pwd2 = prompt(conf)['pwd']
|
||||||
else:
|
else:
|
||||||
print("PASSWORD SAVED")
|
print("PASSWORD SAVED")
|
||||||
return pwd
|
return pwd
|
||||||
|
|
||||||
|
|
||||||
def authenticate():
|
def authenticate():
|
||||||
|
"""
|
||||||
|
Authenticates the user via Ion OAuth
|
||||||
|
"""
|
||||||
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
|
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
|
||||||
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
|
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
|
||||||
|
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
#Linux: chromdriver-linux
|
# Linux: chromdriver-linux
|
||||||
#Macos: chromdriver-mac
|
# Macos: chromdriver-mac
|
||||||
#Windows: chromdriver.exe
|
# Windows: chromdriver.exe
|
||||||
path = os.path.join(os.getcwd(),'chromedriver','chromedriver-linux')
|
path = os.path.join(os.getcwd(), 'chromedriver', 'chromedriver-mac')
|
||||||
|
|
||||||
browser = webdriver.Chrome(path)
|
browser = webdriver.Chrome(path)
|
||||||
|
|
||||||
|
@ -467,7 +607,8 @@ def authenticate():
|
||||||
|
|
||||||
url = browser.current_url
|
url = browser.current_url
|
||||||
gets = url_decode(url.replace("http://localhost:8000/login/?", ""))
|
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)
|
time.sleep(0.25)
|
||||||
|
|
||||||
url = browser.current_url
|
url = browser.current_url
|
||||||
|
@ -489,31 +630,31 @@ def authenticate():
|
||||||
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
data =prompt(questions)
|
data = prompt(questions)
|
||||||
pwd = data['pwd']
|
pwd = data['pwd']
|
||||||
user = data['username']
|
user = data['username']
|
||||||
r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd))
|
r = requests.get(url="http://localhost:8000/api/", auth=(user, pwd))
|
||||||
while(r.status_code != 200):
|
while r.status_code != 200:
|
||||||
print("INCORRECT LOGIN CREDENTIALS")
|
print("INCORRECT LOGIN CREDENTIALS")
|
||||||
r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd))
|
r = requests.get(url="http://localhost:8000/api/", auth=(user, pwd))
|
||||||
data =prompt(questions)
|
data = prompt(questions)
|
||||||
pwd = data['pwd']
|
pwd = data['pwd']
|
||||||
user = data['username']
|
user = data['username']
|
||||||
print(r.status_code)
|
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
|
is_student = False
|
||||||
if(r.status_code == 200):
|
if r.status_code == 200:
|
||||||
is_student = True
|
is_student = True
|
||||||
print("Welcome, student " + user)
|
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()
|
profile = r.json()
|
||||||
username = profile['ion_user']
|
username = profile['ion_user']
|
||||||
grade = profile['grade']
|
grade = profile['grade']
|
||||||
profile = {
|
profile = {
|
||||||
'username':username,
|
'username': username,
|
||||||
'grade':grade,
|
'grade': grade,
|
||||||
'is_student':is_student,
|
'is_student': is_student,
|
||||||
'password':pwd,
|
'password': pwd,
|
||||||
}
|
}
|
||||||
fname = "." + username + "profile"
|
fname = "." + username + "profile"
|
||||||
profileFile = open(fname, "w")
|
profileFile = open(fname, "w")
|
||||||
|
@ -522,13 +663,13 @@ def authenticate():
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Welcome, teacher " + user)
|
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()
|
profile = r.json()
|
||||||
username = profile['ion_user']
|
username = profile['ion_user']
|
||||||
profile = {
|
profile = {
|
||||||
'username':username,
|
'username': username,
|
||||||
'is_student':is_student,
|
'is_student': is_student,
|
||||||
'password':pwd,
|
'password': pwd,
|
||||||
}
|
}
|
||||||
fname = "." + username + "profile"
|
fname = "." + username + "profile"
|
||||||
profileFile = open(fname, "w")
|
profileFile = open(fname, "w")
|
||||||
|
@ -539,11 +680,15 @@ def authenticate():
|
||||||
|
|
||||||
|
|
||||||
def create_server():
|
def create_server():
|
||||||
|
"""
|
||||||
|
Creates a simple HTTP server for creating api requests from the CLI
|
||||||
|
"""
|
||||||
port = 8000
|
port = 8000
|
||||||
handler = http.server.SimpleHTTPRequestHandler
|
handler = http.server.SimpleHTTPRequestHandler
|
||||||
httpd = socketserver.TCPServer(("", port), handler)
|
httpd = socketserver.TCPServer(("", port), handler)
|
||||||
print("serving at port:" + str(port))
|
print("serving at port:" + str(port))
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user