mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-18 03:10:18 -04:00
Merge branch 'development' of github.com:Rushilwiz/SkoolOS into development
This commit is contained in:
commit
8a5e1d2f86
119
CLI/teacher.py
119
CLI/teacher.py
|
@ -29,9 +29,9 @@ from datetime import datetime
|
||||||
def getTeacher(ion_user, password):
|
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: the teacher's password
|
: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 + "/"
|
||||||
r = requests.get(url=URL, auth=(ion_user,password))
|
r = requests.get(url=URL, auth=(ion_user,password))
|
||||||
|
@ -53,10 +53,10 @@ def getTeacher(ion_user, password):
|
||||||
def getDB(user, pwd, url):
|
def getDB(user, pwd, url):
|
||||||
"""
|
"""
|
||||||
Sends a GET request to url
|
Sends a GET request to url
|
||||||
param user: username
|
:param user: username
|
||||||
param pwd: password
|
:param pwd: password
|
||||||
param url: URL for request
|
:param url: URL for request
|
||||||
return: json request response
|
: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))
|
||||||
|
@ -66,11 +66,11 @@ def getDB(user, pwd, url):
|
||||||
def patchDB(user, pwd, data, url):
|
def patchDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PATCH request to url
|
Sends a PATCH request to url
|
||||||
param user: username
|
:param user: username
|
||||||
param pwd: password
|
:param pwd: password
|
||||||
param url: URL for request
|
:param url: URL for request
|
||||||
param data: data to request
|
:param data: data to request
|
||||||
return: json request response
|
: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))
|
||||||
|
@ -81,11 +81,11 @@ def patchDB(user, pwd, data, url):
|
||||||
def postDB(user, pwd, data, url):
|
def postDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a POST request to url
|
Sends a POST request to url
|
||||||
param user: username
|
:param user: username
|
||||||
param pwd: password
|
:param pwd: password
|
||||||
param url: URL for request
|
:param url: URL for request
|
||||||
param data: data to request
|
:param data: data to request
|
||||||
return: json request response
|
: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))
|
||||||
|
@ -96,11 +96,11 @@ def postDB(user, pwd, data, url):
|
||||||
def putDB(user, pwd, data, url):
|
def putDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PUT request to url
|
Sends a PUT request to url
|
||||||
param user: username
|
:param user: username
|
||||||
param pwd: password
|
:param pwd: password
|
||||||
param url: URL for request
|
:param url: URL for request
|
||||||
param data: data to request
|
:param data: data to request
|
||||||
return: json request response
|
: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))
|
||||||
|
@ -111,10 +111,10 @@ def putDB(user, pwd, data, url):
|
||||||
def delDB(user, pwd, url):
|
def delDB(user, pwd, url):
|
||||||
"""
|
"""
|
||||||
Sends a DELETE request to url
|
Sends a DELETE request to url
|
||||||
param user: username
|
:param user: username
|
||||||
param pwd: password
|
:param pwd: password
|
||||||
param url: URL for request
|
:param url: URL for request
|
||||||
return: json request response
|
: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))
|
||||||
|
@ -124,7 +124,7 @@ def delDB(user, pwd, url):
|
||||||
def command(command):
|
def command(command):
|
||||||
"""
|
"""
|
||||||
Runs a shell command
|
Runs a shell command
|
||||||
param command: shell command
|
:param command: shell command
|
||||||
"""
|
"""
|
||||||
ar = []
|
ar = []
|
||||||
command = command.split(" ")
|
command = command.split(" ")
|
||||||
|
@ -145,7 +145,7 @@ class Teacher:
|
||||||
# intitialze fields after GET request
|
# intitialze fields after GET request
|
||||||
"""
|
"""
|
||||||
Initializes a Teacher with the data from the api
|
Initializes a Teacher with the data from the api
|
||||||
param data: api data
|
:param data: api data
|
||||||
"""
|
"""
|
||||||
self.git = data['git']
|
self.git = data['git']
|
||||||
self.username = data['ion_user']
|
self.username = data['ion_user']
|
||||||
|
@ -178,7 +178,7 @@ class Teacher:
|
||||||
def checkClass(self, path):
|
def checkClass(self, path):
|
||||||
"""
|
"""
|
||||||
Checks if a directory is valid for creating a class
|
Checks if a directory is valid for creating a class
|
||||||
param path: path to the new class directory
|
:param path: path to the new class directory
|
||||||
"""
|
"""
|
||||||
cname = path.split("/")
|
cname = path.split("/")
|
||||||
cname = cname[len(cname) - 1]
|
cname = cname[len(cname) - 1]
|
||||||
|
@ -221,7 +221,7 @@ class Teacher:
|
||||||
def checkInDB(self, path):
|
def checkInDB(self, path):
|
||||||
"""
|
"""
|
||||||
Checks if "path" is in the database
|
Checks if "path" is in the database
|
||||||
param path: path to directory
|
:param path: path to directory
|
||||||
"""
|
"""
|
||||||
n = path.split("/")
|
n = path.split("/")
|
||||||
n = n[len(n) - 1]
|
n = n[len(n) - 1]
|
||||||
|
@ -234,7 +234,7 @@ class Teacher:
|
||||||
def addClass(self, path):
|
def addClass(self, path):
|
||||||
"""
|
"""
|
||||||
Creates a class from an existing directory, adding it to the proper git repository and the api
|
Creates a class from an existing directory, adding it to the proper git repository and the api
|
||||||
param path:
|
:param path:
|
||||||
"""
|
"""
|
||||||
cname = path.split("/")
|
cname = path.split("/")
|
||||||
cname = cname[len(cname) - 1]
|
cname = cname[len(cname) - 1]
|
||||||
|
@ -276,7 +276,7 @@ class Teacher:
|
||||||
def makeClass(self, cname):
|
def makeClass(self, cname):
|
||||||
"""
|
"""
|
||||||
Makes a class with its own new directory
|
Makes a class with its own new directory
|
||||||
param cname: name of class
|
:param cname: name of class
|
||||||
"""
|
"""
|
||||||
# check if class exists
|
# check if class exists
|
||||||
path = self.username + "/" + cname
|
path = self.username + "/" + cname
|
||||||
|
@ -314,7 +314,7 @@ class Teacher:
|
||||||
def deleteClass(self, path):
|
def deleteClass(self, path):
|
||||||
"""
|
"""
|
||||||
Deletes an existing class
|
Deletes an existing class
|
||||||
param path: class directory path
|
:param path: class directory path
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
print(path + " does not exist locally.")
|
print(path + " does not exist locally.")
|
||||||
|
@ -348,8 +348,8 @@ class Teacher:
|
||||||
def isStudent(self, student):
|
def isStudent(self, student):
|
||||||
"""
|
"""
|
||||||
Checks if the student exists
|
Checks if the student exists
|
||||||
param student: a student
|
:param student: a student
|
||||||
return: True if student exists, False otherwise
|
:return: True if student exists, False otherwise
|
||||||
"""
|
"""
|
||||||
r = requests.get(url="http://127.0.0.1:8000/api/students/" + student + "/",
|
r = requests.get(url="http://127.0.0.1:8000/api/students/" + student + "/",
|
||||||
auth=(self.username, self.password))
|
auth=(self.username, self.password))
|
||||||
|
@ -360,9 +360,9 @@ class Teacher:
|
||||||
def reqStudent(self, sname, cname):
|
def reqStudent(self, sname, cname):
|
||||||
"""
|
"""
|
||||||
Request student informatiion from the api
|
Request student informatiion from the api
|
||||||
param sname: student's name
|
:param sname: student's name
|
||||||
param cname: class name
|
:param cname: class name
|
||||||
return: True if successful
|
:return: True if successful
|
||||||
"""
|
"""
|
||||||
if not self.isStudent(sname):
|
if not self.isStudent(sname):
|
||||||
print(sname + " does not exist.")
|
print(sname + " does not exist.")
|
||||||
|
@ -406,9 +406,9 @@ class Teacher:
|
||||||
def addStudent(self, sname, cname):
|
def addStudent(self, sname, cname):
|
||||||
"""
|
"""
|
||||||
Adds a student to a class
|
Adds a student to a class
|
||||||
param sname: student name
|
:param sname: student name
|
||||||
param cname: class name
|
:param cname: class name
|
||||||
return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if not self.isStudent(sname):
|
if not self.isStudent(sname):
|
||||||
print(sname + " does not exist.")
|
print(sname + " does not exist.")
|
||||||
|
@ -476,9 +476,9 @@ class Teacher:
|
||||||
def reqAddStudentList(self, array, cname):
|
def reqAddStudentList(self, array, cname):
|
||||||
"""
|
"""
|
||||||
Runs addStudent() on all students in array
|
Runs addStudent() on all students in array
|
||||||
param array: an array of students
|
:param array: an array of students
|
||||||
param cname: class name
|
:param cname: class name
|
||||||
return: students that have not confirmed the request
|
:return: students that have not confirmed the request
|
||||||
"""
|
"""
|
||||||
unconf = []
|
unconf = []
|
||||||
for i in range(len(array)):
|
for i in range(len(array)):
|
||||||
|
@ -492,10 +492,10 @@ class Teacher:
|
||||||
def addAssignment(self, path, course, due):
|
def addAssignment(self, path, course, due):
|
||||||
"""
|
"""
|
||||||
Creates an assignment for "course" that is due on "due"
|
Creates an assignment for "course" that is due on "due"
|
||||||
param path: directory of assignment
|
:param path: directory of assignment
|
||||||
param course: course name
|
:param course: course name
|
||||||
param due: due date
|
:param due: due date
|
||||||
return: False if unsuccessful
|
:return: False if unsuccessful
|
||||||
"""
|
"""
|
||||||
parts = path.split("/")
|
parts = path.split("/")
|
||||||
aname = parts[len(parts) - 1]
|
aname = parts[len(parts) - 1]
|
||||||
|
@ -566,7 +566,7 @@ class Teacher:
|
||||||
'path': path,
|
'path': path,
|
||||||
'classes': course['name'],
|
'classes': course['name'],
|
||||||
'teacher': self.username,
|
'teacher': self.username,
|
||||||
'due_date': due,
|
'due_date': str(due),
|
||||||
'owner':self.id
|
'owner':self.id
|
||||||
}
|
}
|
||||||
postDB(self.username, self.password, ass, 'http://127.0.0.1:8000/api/assignments/')
|
postDB(self.username, self.password, ass, 'http://127.0.0.1:8000/api/assignments/')
|
||||||
|
@ -676,9 +676,9 @@ class Teacher:
|
||||||
def getChanges(self, student, course, commits):
|
def getChanges(self, student, course, commits):
|
||||||
"""
|
"""
|
||||||
Checks for new submissions by a student
|
Checks for new submissions by a student
|
||||||
param student: the student
|
:param student: the student
|
||||||
param course: the course
|
:param course: the course
|
||||||
param commits: commits the CLI has made for the assignment
|
:param commits: commits the CLI has made for the assignment
|
||||||
"""
|
"""
|
||||||
course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course + "/")
|
course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course + "/")
|
||||||
ar = self.getCommits(student, course['name'], commits)
|
ar = self.getCommits(student, course['name'], commits)
|
||||||
|
@ -735,14 +735,16 @@ class Teacher:
|
||||||
def comment(self):
|
def comment(self):
|
||||||
"""
|
"""
|
||||||
The ultimate form of laughter
|
The ultimate form of laughter
|
||||||
return: pure joy
|
:return: pure joy
|
||||||
"""
|
"""
|
||||||
print("heheheh")
|
print("heheheh")
|
||||||
|
|
||||||
|
|
||||||
# data = getTeacher("eharris1","PWD")
|
data = getTeacher("eharris1",'hackgroup1')
|
||||||
# print(data)
|
# print(data)
|
||||||
#t = Teacher(data, "PWD")
|
t = Teacher(data, 'hackgroup1')
|
||||||
|
t.addAssignment("eharris1/Truck_eharris1/Assignment1", "Truck_eharris1", '2020-08-11 16:58:33.383124')
|
||||||
|
|
||||||
# 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']
|
||||||
|
@ -752,6 +754,13 @@ class Teacher:
|
||||||
# t.getChanges('2022rkhondak','APLit_eharris1', 10)
|
# t.getChanges('2022rkhondak','APLit_eharris1', 10)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
{
|
||||||
|
"name": "a",
|
||||||
|
"due_date": '2020-08-11 16:58:33.383124',
|
||||||
|
"path": "",
|
||||||
|
"teacher": ""
|
||||||
|
}
|
||||||
|
|
||||||
TO-DO
|
TO-DO
|
||||||
- More checks
|
- More checks
|
||||||
- add students to APLit_eharris1
|
- add students to APLit_eharris1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user