mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
students fix
This commit is contained in:
parent
92ff41ba60
commit
3663fd1c90
128
CLI/student.py
128
CLI/student.py
|
@ -14,28 +14,22 @@ import datetime
|
||||||
|
|
||||||
# get teacher info from api
|
# get teacher info from api
|
||||||
def getStudent(ion_user, password):
|
def getStudent(ion_user, password):
|
||||||
"""
|
|
||||||
Get's student information from the api
|
|
||||||
:param ion_user: a student
|
|
||||||
:return: student information or error
|
|
||||||
"""
|
|
||||||
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
||||||
r = requests.get(url=URL, auth=(ion_user, password))
|
r = requests.get(url=URL, auth=(ion_user, password))
|
||||||
if (r.status_code == 200):
|
if (r.status_code == 200):
|
||||||
data = r.json()
|
data = r.json()
|
||||||
return data
|
return data
|
||||||
elif r.status_code == 404:
|
elif (r.status_code == 404):
|
||||||
return None
|
return None
|
||||||
print("Make new account!")
|
print("Make new account!")
|
||||||
elif r.status_code == 403:
|
elif (r.status_code == 403):
|
||||||
return None
|
return None
|
||||||
print("Invalid username/password")
|
print("Invalid username/password")
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
print(r.status_code)
|
print(r.status_code)
|
||||||
|
|
||||||
|
#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 the URL
|
||||||
|
@ -43,10 +37,9 @@ def getDB(user, pwd, url):
|
||||||
"""
|
"""
|
||||||
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))
|
||||||
return r.json()
|
return(r.json())
|
||||||
|
|
||||||
|
#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 the URL
|
||||||
|
@ -58,7 +51,7 @@ def patchDB(user, pwd, data, url):
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
# 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 the URL
|
||||||
|
@ -70,7 +63,7 @@ def postDB(user, pwd, data, url):
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
# 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 the URL
|
||||||
|
@ -82,7 +75,7 @@ def putDB(user, pwd, data, url):
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
# 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 the URL
|
||||||
|
@ -94,10 +87,6 @@ def delDB(user, pwd, url):
|
||||||
|
|
||||||
|
|
||||||
def command(command):
|
def command(command):
|
||||||
"""
|
|
||||||
Runs a shell command
|
|
||||||
:param command: shell command
|
|
||||||
"""
|
|
||||||
ar = []
|
ar = []
|
||||||
command = command.split(" ")
|
command = command.split(" ")
|
||||||
for c in command:
|
for c in command:
|
||||||
|
@ -116,10 +105,6 @@ class Student:
|
||||||
def __init__(self, data, password):
|
def __init__(self, data, password):
|
||||||
# teacher info already stored in API
|
# teacher info already stored in API
|
||||||
# intitialze fields after GET request
|
# intitialze fields after GET request
|
||||||
"""
|
|
||||||
Initializes a Student with data from the api
|
|
||||||
:param data: api data
|
|
||||||
"""
|
|
||||||
self.git = data['git']
|
self.git = data['git']
|
||||||
self.username = data['ion_user']
|
self.username = data['ion_user']
|
||||||
self.url = "http://127.0.0.1:8000/api/students/" + self.username + "/"
|
self.url = "http://127.0.0.1:8000/api/students/" + self.username + "/"
|
||||||
|
@ -166,8 +151,8 @@ class Student:
|
||||||
self.snew = str(data['added_to'])
|
self.snew = str(data['added_to'])
|
||||||
self.repo = data['repo']
|
self.repo = data['repo']
|
||||||
|
|
||||||
if os.path.isdir(self.username) == False:
|
if (os.path.isdir(self.username) == False):
|
||||||
if self.repo == "":
|
if (self.repo == ""):
|
||||||
user = self.git
|
user = self.git
|
||||||
pwd = input("Enter Github password: ")
|
pwd = input("Enter Github password: ")
|
||||||
# curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos
|
# curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos
|
||||||
|
@ -191,18 +176,11 @@ class Student:
|
||||||
print("Synced to " + self.username)
|
print("Synced to " + self.username)
|
||||||
|
|
||||||
def getClasses(self):
|
def getClasses(self):
|
||||||
"""
|
|
||||||
Gets a lists of classes the student is enrolled in
|
|
||||||
"""
|
|
||||||
classes = self.classes
|
classes = self.classes
|
||||||
for c in classes:
|
for c in classes:
|
||||||
print(c['name'])
|
print(c['name'])
|
||||||
|
|
||||||
def getAssignments(self, span):
|
def getAssignments(self, course, span):
|
||||||
"""
|
|
||||||
Gets a list of assignments the student has
|
|
||||||
:param span: time span to check
|
|
||||||
"""
|
|
||||||
span = datetime.timedelta(span, 0)
|
span = datetime.timedelta(span, 0)
|
||||||
classes = self.classes
|
classes = self.classes
|
||||||
for c in classes:
|
for c in classes:
|
||||||
|
@ -217,7 +195,7 @@ class Student:
|
||||||
diff = now - due
|
diff = now - due
|
||||||
zero = datetime.timedelta(0, 0)
|
zero = datetime.timedelta(0, 0)
|
||||||
# check due ddate is in span range is now past date (- timdelta)
|
# check due ddate is in span range is now past date (- timdelta)
|
||||||
if diff < span and diff > zero:
|
if (diff < span and diff > zero):
|
||||||
print(a + " due in:" + str(now - due))
|
print(a + " due in:" + str(now - due))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -226,9 +204,6 @@ class Student:
|
||||||
|
|
||||||
# update API and Github, all assignments / classes
|
# update API and Github, all assignments / classes
|
||||||
def update(self):
|
def update(self):
|
||||||
"""
|
|
||||||
Updates the api, github, and all assignments and classes with new information
|
|
||||||
"""
|
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
os.chdir(self.username)
|
os.chdir(self.username)
|
||||||
command("git checkout master")
|
command("git checkout master")
|
||||||
|
@ -251,11 +226,7 @@ class Student:
|
||||||
|
|
||||||
# updates 1 class, does not switch to master
|
# updates 1 class, does not switch to master
|
||||||
def updateClass(self, course):
|
def updateClass(self, course):
|
||||||
"""
|
if ((course in self.sclass) == False):
|
||||||
Updates a class with new information
|
|
||||||
:param course: class name in the format <course-name>_<ion_user>
|
|
||||||
"""
|
|
||||||
if (course in self.sclass) == False:
|
|
||||||
print("Class not found")
|
print("Class not found")
|
||||||
return
|
return
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
|
@ -270,20 +241,16 @@ class Student:
|
||||||
|
|
||||||
# add classes from 'new' field
|
# add classes from 'new' field
|
||||||
def addClass(self, cid):
|
def addClass(self, cid):
|
||||||
"""
|
|
||||||
Add student to a class
|
|
||||||
:param cid: the id number of the class
|
|
||||||
:return: data from the class, None if an error occures
|
|
||||||
"""
|
|
||||||
data = getDB(self.username, self.password,'http://127.0.0.1:8000/api/classes/' + str(cid))
|
data = getDB(self.username, self.password,'http://127.0.0.1:8000/api/classes/' + str(cid))
|
||||||
if ((cid in self.snew) == False or (self.username in data['confirmed'])):
|
if ((cid in self.snew) == False or (self.username in data['confirmed'])):
|
||||||
print("Already enrolled in this class.")
|
print("Already enrolled in this class.")
|
||||||
return None
|
return None
|
||||||
if (cid in self.sclass) or not (self.username in data['unconfirmed']):
|
if ((cid in self.sclass) or (self.username in data['unconfirmed']) == False):
|
||||||
print("Not added by teacher yet.")
|
print("Not added by teacher yet.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# add class teacher as collaborator to student repo
|
# add class teacher as cocllaborator to student repo
|
||||||
print(os.getcwd())
|
print(os.getcwd())
|
||||||
pwd = input("Enter Github password: ")
|
pwd = input("Enter Github password: ")
|
||||||
tgit = getDB(self.username, self.password,"http://127.0.0.1:8000/api/teachers/" + data['teacher'] + "/")['git']
|
tgit = getDB(self.username, self.password,"http://127.0.0.1:8000/api/teachers/" + data['teacher'] + "/")['git']
|
||||||
|
@ -303,7 +270,7 @@ class Student:
|
||||||
# os.chdir(self.username)
|
# os.chdir(self.username)
|
||||||
|
|
||||||
# push to git, start at master
|
# push to git, start at master
|
||||||
# os.chdir(self.username)
|
#os.chdir(self.username)
|
||||||
command("git checkout master")
|
command("git checkout master")
|
||||||
command("git branch " + data['name'])
|
command("git branch " + data['name'])
|
||||||
command("git commit -m initial")
|
command("git commit -m initial")
|
||||||
|
@ -325,7 +292,7 @@ class Student:
|
||||||
user = self.git
|
user = self.git
|
||||||
|
|
||||||
self.classes.append(data)
|
self.classes.append(data)
|
||||||
if len(self.sclass) == 0:
|
if (len(self.sclass) == 0):
|
||||||
self.sclass = data['name']
|
self.sclass = data['name']
|
||||||
else:
|
else:
|
||||||
self.sclass = self.sclass + "," + str(data['name'])
|
self.sclass = self.sclass + "," + str(data['name'])
|
||||||
|
@ -334,7 +301,7 @@ class Student:
|
||||||
snew = ""
|
snew = ""
|
||||||
new = []
|
new = []
|
||||||
for i in range(len(self.new)):
|
for i in range(len(self.new)):
|
||||||
if self.new[i]['name'] == data['name']:
|
if (self.new[i]['name'] == data['name']):
|
||||||
del self.new[i]
|
del self.new[i]
|
||||||
# recreate sclass field, using ids
|
# recreate sclass field, using ids
|
||||||
for c in self.new:
|
for c in self.new:
|
||||||
|
@ -354,12 +321,46 @@ class Student:
|
||||||
print(patchDB(self.username, self.password,data, self.url))
|
print(patchDB(self.username, self.password,data, self.url))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def submit(self, path):
|
||||||
|
# 2022rkhondak/English11_eharris1/Essay1
|
||||||
|
# check if valid assignment
|
||||||
|
parts = path.split("/")
|
||||||
|
if (len(parts) != 3):
|
||||||
|
print("Assignment path too short")
|
||||||
|
return
|
||||||
|
isclass = False
|
||||||
|
for c in self.classes:
|
||||||
|
if (c['name'] == parts[1]):
|
||||||
|
isclass == True
|
||||||
|
break
|
||||||
|
if (parts[0] != self.username and isclass and os.path.isdir(path) == False):
|
||||||
|
print("Not valid assignment")
|
||||||
|
return
|
||||||
|
if ((parts[1] + "/" + parts[2]) in self.completed):
|
||||||
|
print(parts[2] + " already submited. ")
|
||||||
|
# return
|
||||||
|
resp = input("Are you sure you want to submit? You cannot do this again.(y/N) ")
|
||||||
|
if (resp == 'y'):
|
||||||
|
os.chdir(self.username + "/" + parts[1])
|
||||||
|
command("git add .")
|
||||||
|
command("git commit -m submit")
|
||||||
|
command("git tag " + parts[1] + "-final")
|
||||||
|
command("git push -u origin " + self.username + " --tags")
|
||||||
|
self.completed = self.completed + "," + parts[1] + "/" + parts[2]
|
||||||
|
data = {
|
||||||
|
'user': self.user,
|
||||||
|
'git': self.git,
|
||||||
|
'ion_user': self.username,
|
||||||
|
'student_id': self.student_id,
|
||||||
|
'added_to': self.snew,
|
||||||
|
'url': self.url,
|
||||||
|
'classes': self.sclass,
|
||||||
|
'grade': self.grade,
|
||||||
|
'completed': self.completed
|
||||||
|
}
|
||||||
|
# print(putDB(data, "http://127.0.0.1:8000/api/students/" + self.username + "/"))
|
||||||
|
|
||||||
def viewClass(self, courses):
|
def viewClass(self, courses):
|
||||||
"""
|
|
||||||
Sets the current git branch to view each class in courses
|
|
||||||
:param courses: a list of classes
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
self.update()
|
self.update()
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
os.chdir(self.username)
|
os.chdir(self.username)
|
||||||
|
@ -374,20 +375,11 @@ class Student:
|
||||||
return
|
return
|
||||||
|
|
||||||
def exitCLI(self):
|
def exitCLI(self):
|
||||||
"""
|
|
||||||
Exits the cli
|
|
||||||
"""
|
|
||||||
print(os.getcwd())
|
print(os.getcwd())
|
||||||
self.update()
|
self.update()
|
||||||
command("git checkout master")
|
command("git checkout master")
|
||||||
|
|
||||||
def submit(self, course, assignment):
|
def submit(self, course, assignment):
|
||||||
"""
|
|
||||||
Submits an assignment
|
|
||||||
:param course: the class the assignment belongs to
|
|
||||||
:param assignment: the assignment
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
os.chdir(self.username)
|
os.chdir(self.username)
|
||||||
print(os.getcwd())
|
print(os.getcwd())
|
||||||
|
@ -402,7 +394,7 @@ class Student:
|
||||||
inclass = True
|
inclass = True
|
||||||
oname = a + "_" + course
|
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)
|
||||||
command('git checkout master')
|
command('git checkout master')
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
|
@ -414,7 +406,7 @@ 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 = oname + "," + self.completed
|
self.completed = assignment + "," + self.completed
|
||||||
data = {
|
data = {
|
||||||
'completed': self.completed
|
'completed': self.completed
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user