From 38532e7bfa035c52da16b736f0fd8d8002f5b95c Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 17:57:21 -0400 Subject: [PATCH 01/10] finished documenting skoolos.py --- CLI/student.py | 164 +++++++++++------- CLI/teacher.py | 2 +- skoolos.py | 450 +++++++++++++++++++++++++++++-------------------- 3 files changed, 365 insertions(+), 251 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index a97da2c..d215337 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -14,52 +14,89 @@ import datetime # get teacher info from api def getStudent(ion_user): + """ + 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 + "/" r = requests.get(url=URL, auth=('raffukhondaker', 'hackgroup1')) - if (r.status_code == 200): + if r.status_code == 200: data = r.json() return data - elif (r.status_code == 404): + elif r.status_code == 404: return None print("Make new account!") - elif (r.status_code == 403): + elif r.status_code == 403: return None print("Invalid username/password") else: return None print(r.status_code) -#makes a GET request to given url, returns dict + +# makes a GET request to given url, returns dict def getDB(url): + """ + Sends a GET request to the URL + :param url: URL for request + """ r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1')) 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(data, url): - r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + """ + Sends a PATCH request to the URL + :param data: + :param url: URL for request + """ + r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("PATCH:" + str(r.status_code)) - 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(data, url): + """ + Sends a POST request to the URL + :param data: + :param url: URL for request + """ r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("POST:" + str(r.status_code)) - 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(data, url): + """ + Sends a PUT request to the URL + :param data: + :param url: URL for request + """ r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("PUT:" + str(r.status_code)) - 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(url): + """ + Sends a DELETE request to the URL + :param url: URL for request + """ r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1')) print("DELETE:" + str(r.status_code)) def command(command): + """ + Runs a shell command + :param command: shell command + """ ar = [] command = command.split(" ") for c in command: @@ -78,6 +115,10 @@ class Student: def __init__(self, data): # teacher info already stored in API # intitialze fields after GET request + """ + Initializes a Student with data from the api + :param data: api data + """ self.git = data['git'] self.username = data['ion_user'] self.url = "http://127.0.0.1:8000/api/students/" + self.username + "/" @@ -122,8 +163,8 @@ class Student: self.snew = str(data['added_to']) self.repo = data['repo'] - if (os.path.isdir(self.username) == False): - if (self.repo == ""): + if os.path.isdir(self.username) == False: + if self.repo == "": user = self.git pwd = input("Enter Github password: ") # curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos @@ -147,11 +188,18 @@ class Student: print("Synced to " + self.username) def getClasses(self): + """ + Gets a lists of classes the student is enrolled in + """ classes = self.classes for c in classes: print(c['name']) - def getAssignments(self, course, span): + def getAssignments(self, span): + """ + Gets a list of assignments the student has + :param span: time span to check + """ span = datetime.timedelta(span, 0) classes = self.classes for c in classes: @@ -166,7 +214,7 @@ class Student: diff = now - due zero = datetime.timedelta(0, 0) # 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)) except Exception as e: @@ -175,6 +223,9 @@ class Student: # update API and Github, all assignments / classes def update(self): + """ + Updates the api, github, and all assignments and classes with new information + """ cdir = os.getcwd() os.chdir(self.username) command("git checkout master") @@ -197,7 +248,11 @@ class Student: # updates 1 class, does not switch to master def updateClass(self, course): - if ((course in self.sclass) == False): + """ + Updates a class with new information + :param course: class name in the format _ + """ + if (course in self.sclass) == False: print("Class not found") return cdir = os.getcwd() @@ -212,16 +267,20 @@ class Student: # add classes from 'new' field 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('http://127.0.0.1:8000/api/classes/' + str(cid)) - if ((cid in self.snew) == False or (self.username in data['confirmed'])): + if not (cid in self.snew) or (self.username in data['confirmed']): print("Already enrolled in this class.") return None - if ((cid in self.sclass) or (self.username in data['unconfirmed']) == False): + if (cid in self.sclass) or not (self.username in data['unconfirmed']): print("Not added by teacher yet.") return None - # add class teacher as cocllaborator to student repo + # add class teacher as collaborator to student repo print(os.getcwd()) pwd = input("Enter Github password: ") tgit = getDB("http://127.0.0.1:8000/api/teachers/" + data['teacher'] + "/")['git'] @@ -241,7 +300,7 @@ class Student: # os.chdir(self.username) # push to git, start at master - #os.chdir(self.username) + # os.chdir(self.username) command("git checkout master") command("git branch " + data['name']) command("git commit -m initial") @@ -263,7 +322,7 @@ class Student: user = self.git self.classes.append(data) - if (len(self.sclass) == 0): + if len(self.sclass) == 0: self.sclass = data['name'] else: self.sclass = self.sclass + "," + str(data['name']) @@ -272,7 +331,7 @@ class Student: snew = "" 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] # recreate sclass field, using ids for c in self.new: @@ -292,46 +351,12 @@ class Student: print(patchDB(data, self.url)) 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): + """ + Sets the current git branch to view each class in courses + :param courses: a list of classes + :return: + """ self.update() cdir = os.getcwd() os.chdir(self.username) @@ -346,11 +371,20 @@ class Student: return def exitCLI(self): + """ + Exits the cli + """ print(os.getcwd()) self.update() command("git checkout master") def submit(self, course, assignment): + """ + Submits an assignment + :param course: the class the assignment belongs to + :param assignment: the assignment + :return: + """ cdir = os.getcwd() os.chdir(self.username) print(os.getcwd()) @@ -364,7 +398,7 @@ class Student: if a == assignment: inclass = True break - if (inclass == False): + if inclass == False: print(assignment + " not an assignment of " + course) command('git checkout master') os.chdir(cdir) diff --git a/CLI/teacher.py b/CLI/teacher.py index c332b3f..0f1eaa7 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -87,7 +87,7 @@ def putDB(data, url): Sends a PUT request to the URL :param data: :param url: URL for request - """ + """ r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("PUT:" + str(r.status_code)) return r.json() diff --git a/skoolos.py b/skoolos.py index 2941c21..382eff0 100644 --- a/skoolos.py +++ b/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("██╔════╝██║░██╔╝██╔══██╗██╔══██╗██║░░░░░  ██╔══██╗██╔════╝") @@ -38,13 +43,13 @@ def main(): if not (os.path.exists(".sprofile") or os.path.exists(".tprofile")): 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() @@ -53,109 +58,140 @@ 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 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 + u = int(prompt(user)['user'].split(")")[0]) - 1 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) student.update() EXIT = False - while(not EXIT): + while not EXIT: course = chooseClassStudent(student) 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"] + student.getAssignments(course, 100) + choices = ["Save", "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 - + ################################################ TEACHER METHODS def chooseGeneralTeacher(teacher): + """ + Presents teachers with their options + :param teacher: a teacher + :return: a course prompt + """ carray = [] for c in teacher.classes: carray.append(c) 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 teacherCLI(user, password): + """ + The teachers' view of the CLI + :param user: username + :param password: password + """ from CLI import teacher data = getUser(user, password, 'teacher') print(data) @@ -171,45 +207,45 @@ def teacherCLI(user, password): 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 = chooseGeneralTeacher(teacher) if course == "Exit SkoolOS": teacher.exitCLI() if course == "Make New Class": questions = [ - { - 'type': 'input', - 'name': 'cname', - 'message': 'Class Name (Must be: _): ', - }, + { + 'type': 'input', + 'name': 'cname', + 'message': 'Class Name (Must be: _): ', + }, ] cname = prompt(questions)['cname'] print(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': sys.exit(0) print(path + " is not a valid path") path = input("Enter file path ('N' to exit): ") @@ -224,46 +260,46 @@ def teacherCLI(user, password): teacher.addStudent(s, course) options = ['1) Request Student', "2) Add assignment", "3) View student information", "Exit"] questions = [ - { - 'type': 'list', - 'name': 'course', - 'choices':options, - 'message': 'Select option: ', - }, - ] - option = prompt(questions)['course'].split(")")[0] - if(option == '1'): - 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): ', - }, + 'name': 'course', + 'choices': options, + 'message': 'Select option: ', + }, + ] + option = prompt(questions)['course'].split(")")[0] + if option == '1': + 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): ', + }, ] 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) - 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): ") @@ -272,7 +308,7 @@ def teacherCLI(user, password): teacher.reqAddStudentList(students, course) else: sys.exit(0) - if(option == '2'): + if option == '2': nlist = os.listdir(teacher.username + "/" + course) alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] print(nlist) @@ -281,35 +317,34 @@ def teacherCLI(user, password): 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") sys.exit(0) 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 @@ -317,94 +352,133 @@ def teacherCLI(user, password): 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) + ###################################################################### 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 + "/" - 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 + """ + 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 + "/" + 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(data, url): - r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("PATH:" + str(r.status_code)) - return(r.json()) + return r.json() + def getDB(url): - r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) + """ + Sends a GET request to the URL + :param url: URL for request + """ + r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1')) print("GET:" + str(r.status_code)) - return(r.json()) + return r.json() + def postDB(data, url): - r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + """ + Sends a POST request to the URL + :param url: URL for request + """ + r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("POST:" + str(r.status_code)) - return(r.json()) + return r.json() + def putDB(data, url): - r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + """ + Sends a PUT request to the URL + :param url: URL for request + """ + r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("PUT:" + str(r.status_code)) - return(r.json()) + return r.json() + def delDB(url): - r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) + """ + Sends a DEL request to the URL + :param url: URL for request + """ + r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1')) 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 - if('CLI' in os.getcwd()): - path = os.path.join(os.getcwd(), '../','chromedriver-mac') + # Linux: chromdriver-linux + # Macos: chromdriver-mac + # Windows: chromdriver.exe + if 'CLI' in os.getcwd(): + path = os.path.join(os.getcwd(), '../', 'chromedriver-mac') else: path = os.path.join(os.getcwd(), 'chromedriver-mac') @@ -417,7 +491,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 @@ -428,42 +503,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, } profileFile = open(".sprofile", "w") profileFile.write(json.dumps(profile)) @@ -471,26 +546,31 @@ 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, } profileFile = open(".tprofile", "w") profileFile.write(json.dumps(profile)) profileFile.close() - sys.exit + sys.exit(0) + 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() From 19105021612f81a50d658daba5fe4188d47e6fa8 Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 19:12:12 -0400 Subject: [PATCH 02/10] manually fixed skoolos.py --- skoolos.py | 367 +++++++++++++++++++++++++++++------------------------ 1 file changed, 199 insertions(+), 168 deletions(-) diff --git a/skoolos.py b/skoolos.py index 382eff0..453832d 100644 --- a/skoolos.py +++ b/skoolos.py @@ -163,197 +163,228 @@ def classOptionsStudent(student, course): ################################################ TEACHER METHODS -def chooseGeneralTeacher(teacher): - """ - Presents teachers with their options - :param teacher: a teacher - :return: a course prompt - """ - carray = [] - for c in teacher.classes: - carray.append(c) - carray.append("Make New Class") - carray.append("Exit SkoolOS") - courses = [ - { - 'type': 'list', - 'name': 'course', - 'choices': carray, - 'message': 'Select class: ', - }, - ] - course = prompt(courses)['course'] - return course - - def teacherCLI(user, password): - """ - The teachers' view of the CLI - :param user: username - :param password: password - """ from CLI import teacher data = getUser(user, password, 'teacher') print(data) - teacher = teacher.Teacher(data) + teacher = teacher.Teacher(data, password) + EXIT = False # 1. make a class # 2. add studeents to an existing class # 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" + course = chooseGeneralTeacher(teacher) + if course == "Exit SkoolOS": + EXIT = True + elif course == "Make New Class": + EXIT = makeClassTeacher(teacher) + #selected a class + else: + option = classOptionsTeacher(teacher, course) + if(option == '1'): + EXIT = addStudentsTeacher(teacher, course) + elif(option == '2'): + EXIT = addAssignmentTeacher(teacher, course) + elif(option == '3'): + EXIT = viewStudentsTeacher(teacher, course) + else: + EXIT = True + +def chooseGeneralTeacher(teacher): carray = [] for c in teacher.classes: carray.append(c) 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 = chooseGeneralTeacher(teacher) - if course == "Exit SkoolOS": - teacher.exitCLI() - if course == "Make New Class": + course = prompt(courses)['course'] + return course + +def makeClassTeacher(teacher): + questions = [ + { + 'type': 'input', + 'name': 'cname', + 'message': 'Class Name (Must be: _): ', + }, + ] + 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: _): ', - }, + { + 'type': 'input', + 'name': 'cname', + 'message': 'Class Name (Must be: _): ', + }, ] cname = prompt(questions)['cname'] - print(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): ', - }, - ] - choice = prompt(questions)['students'].split(")")[0] - if "1" == choice: - s = input("Student name: ") - teacher.addStudent(s, cname) - 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': - sys.exit(0) - print(path + " is not a valid path") - path = input("Enter file path ('N' to exit): ") - f = open(path, 'r') - students = f.read().splitlines() - teacher.reqAddStudentList(students, 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): ', + }, + ] + choice = prompt(questions)['students'].split(")")[0] + if("1" == choice): + s = input("Student name: ") + teacher.addStudent(s, cname) + 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'): + return True + print(path + " is not a valid path") + path = input("Enter file path ('N' to exit): ") + f = open(path, 'r') + students = f.read().splitlines() + 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'] + for s in unconf: + 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: ', + }, + ] + 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): ', + }, + ] + schoice = prompt(questions)['students'].split(")")[0] + if(schoice == '1'): + questions = [ + { + 'type': 'input', + 'name': 'student', + 'message': 'Student Name: ', + }, + ] + s = prompt(questions)['student'] + teacher.reqStudent(s, course) + return False + if(schoice == '2'): + questions = [ + { + 'type': 'input', + 'name': 'path', + 'message': 'Path: ', + }, + ] + path = prompt(questions)['path'] + 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): ") + f = open(path, 'r') + students = f.read().splitlines() + teacher.reqAddStudentList(students, course) + return False else: - print("Class: " + course) - unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] - for s in unconf: - teacher.addStudent(s, course) - options = ['1) Request Student', "2) Add assignment", "3) View student information", "Exit"] - questions = [ - { - 'type': 'list', - 'name': 'course', - 'choices': options, - 'message': 'Select option: ', - }, - ] - option = prompt(questions)['course'].split(")")[0] - if option == '1': - 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): ', - }, - ] - schoice = prompt(questions)['students'].split(")")[0] - if schoice == '1': - questions = [ - { - 'type': 'input', - 'name': 'student', - 'message': 'Student Name: ', - }, - ] - s = prompt(questions)['student'] - teacher.reqStudent(s, course) - if schoice == '2': - questions = [ - { - 'type': 'input', - 'name': 'path', - 'message': 'Path: ', - }, - ] - path = prompt(questions)['path'] - 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): ") - f = open(path, 'r') - students = f.read().splitlines() - teacher.reqAddStudentList(students, course) - else: - sys.exit(0) - if option == '2': - nlist = os.listdir(teacher.username + "/" + course) - alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] - print(nlist) - tlist = [] - b = True - 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) - b = False - if not os.path.isdir(teacher.username + "/" + course + "/" + n): - b = False - if b: - tlist.append(n) + return True - nlist = tlist - if len(nlist) == 0: - print("No new assignments found") - sys.exit(0) - questions = [ - { - 'type': 'list', - 'choices': nlist, - 'name': 'assignment', - 'message': 'Select new assignment: ', - }, - ] - ass = prompt(questions)['assignment'] - apath = teacher.username + "/" + course + "/" + ass +def addAssignmentTeacher(teacher, course): + nlist = os.listdir(teacher.username + "/" + course) + alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments'] + print(nlist) + tlist = [] + b = True + 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) + b = False + if(not os.path.isdir(teacher.username + "/" + course + "/" + n)): + b = False + if(b): + tlist.append(n) + + + nlist = tlist + 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") + return False + questions = [ + { + '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.strip() + f = False + while(not f): + try: + datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') + f = True + except: + 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.strip() - f = False - while not f: - try: - datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') - f = True - except: - print("Due-date format is incorrect.") - print(due) - due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" - teacher.addAssignment(apath, course, due) + 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"] + unconf = data['unconfirmed'] + print("Studented in class: ") + for s in students: + print(s) + print("Requsted Students: ") + 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']))): + 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 + "/")) ###################################################################### From d4be5f9eb86752b8ef116617f2adbf4c84e00374 Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 19:12:34 -0400 Subject: [PATCH 03/10] formatting --- skoolos.py | 162 +++++++++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 78 deletions(-) diff --git a/skoolos.py b/skoolos.py index 453832d..6f2ba9f 100644 --- a/skoolos.py +++ b/skoolos.py @@ -174,25 +174,26 @@ 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: 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: @@ -200,56 +201,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: _): ', - }, - ] - 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: _): ', }, + ] + 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: _): ', + }, ] 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): ") @@ -258,6 +260,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'] @@ -265,49 +268,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): ") @@ -318,6 +322,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'] @@ -327,36 +332,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 @@ -364,10 +369,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"] @@ -379,7 +385,7 @@ def viewStudentsTeacher(teacher, course): for s in unconf: print(s) student = input("View student (Enter student's ion username): ") - while((not student in str(data['confirmed'])) or (not student in str(data['unconfirmed']))): + while ((not student in str(data['confirmed'])) or (not student in str(data['unconfirmed']))): print("Student not affiliated with class") student = input("View student ('N' to exit): ") if student == 'N': @@ -523,7 +529,7 @@ 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/ + not browser.current_url == "http://localhost:8000/"): # http://localhost:8000/ time.sleep(0.25) url = browser.current_url From 1c2a344ccea167604e69ce2f1eef5871ca026681 Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 19:40:45 -0400 Subject: [PATCH 04/10] cleaned up code in skoolos.py --- skoolos.py | 184 ++++++++++++++++++++++++++++------------------------- 1 file changed, 98 insertions(+), 86 deletions(-) diff --git a/skoolos.py b/skoolos.py index cc8fe8c..68afc8c 100644 --- a/skoolos.py +++ b/skoolos.py @@ -77,7 +77,7 @@ def main(): }, ] u = int(prompt(user)['user'].split(")")[0]) - 1 - if(u+1 == count): + if u + 1 == count: authenticate() return data = info[u] @@ -89,6 +89,7 @@ def main(): else: teacherCLI(USER, PWD) + #################################################################################################### STUDENT METHODS def studentCLI(user, password): @@ -104,7 +105,7 @@ def studentCLI(user, password): EXIT = False while not EXIT: course = chooseClassStudent(student) - if(course == "Exit SkoolOS"): + if course == "Exit SkoolOS": return EXIT = classOptionsStudent(student, course) @@ -171,6 +172,11 @@ def classOptionsStudent(student, course): #################################################################################################### TEACHER METHODS def teacherCLI(user, password): + """ + The CLI for teachers to access + :param user: teachers username + :param password: teachers password + """ from CLI import teacher data = getUser(user, password, 'teacher') print(data) @@ -181,25 +187,26 @@ 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: 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: @@ -207,56 +214,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: _): ', - }, - ] - 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: _): ', }, + ] + 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: _): ', + }, ] 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): ") @@ -265,6 +273,7 @@ def makeClassTeacher(teacher): teacher.reqAddStudentList(students, cname) return False + def classOptionsTeacher(teacher, course): print("Class: " + course) unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed'] @@ -272,49 +281,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): ") @@ -325,6 +335,7 @@ def addStudentsTeacher(teacher, course): else: return True + def addAssignmentTeacher(teacher, course): nlist = os.listdir(teacher.username + "/" + course) alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments'] @@ -334,36 +345,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 @@ -371,10 +382,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"] @@ -386,7 +398,7 @@ def viewStudentsTeacher(teacher, course): for s in unconf: print(s) student = input("View student (Enter student's ion username): ") - while((not student in str(data['confirmed'])) or (not student in str(data['unconfirmed']))): + while (not student in str(data['confirmed'])) or (not student in str(data['unconfirmed'])): print("Student not affiliated with class") student = input("View student ('N' to exit): ") if student == 'N': @@ -394,7 +406,6 @@ def viewStudentsTeacher(teacher, course): print(getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/")) - ############################################################################################################################################ @@ -427,32 +438,33 @@ def getUser(ion_user, password, utype): print(r.status_code) return None + def patchDB(USER, PWD, url, data): - r = requests.patch(url = url, data=data, auth=(USER,PWD)) + r = requests.patch(url=url, data=data, auth=(USER, PWD)) print("PATH:" + str(r.status_code)) return r.json() 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)) return r.json() def postDB(USER, PWD, url, data): - 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)) return r.json() def putDB(USER, PWD, url, data): - 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)) return r.json() def delDB(USER, PWD, url): - r = requests.delete(url = url, auth=(USER,PWD)) + r = requests.delete(url=url, auth=(USER, PWD)) print("DELETE:" + str(r.status_code)) return None @@ -500,7 +512,7 @@ def authenticate(): # Linux: chromdriver-linux # Macos: chromdriver-mac # Windows: chromdriver.exe - path = os.path.join(os.getcwd(),'chromedriver','chromedriver-mac') + path = os.path.join(os.getcwd(), 'chromedriver', 'chromedriver-mac') browser = webdriver.Chrome(path) From 401fbaaee913e242330361a78459849292199184 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 19:43:26 -0400 Subject: [PATCH 05/10] student submissions failed --- CLI/student.py | 11 +++- CLI/teacher.py | 4 +- .../English12_eharris1/Essay1/instruct.txt | 0 skoolos.py | 54 +++++++++++++++++-- 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 eharris1/English12_eharris1/Essay1/instruct.txt diff --git a/CLI/student.py b/CLI/student.py index ae61396..b44d3a6 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -112,6 +112,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 +386,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 +406,11 @@ class Student: command("git tag " + assignment + "-final") command("git push -u origin " + course + " --tags") command('git checkout master') + self.completed = oname + "," + self.completed + data = { + 'completed': self.completed + } + patchDB(self.username, self.password, data, self.url) os.chdir(cdir) diff --git a/CLI/teacher.py b/CLI/teacher.py index 363d80c..88c0608 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -604,7 +604,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 +697,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) diff --git a/eharris1/English12_eharris1/Essay1/instruct.txt b/eharris1/English12_eharris1/Essay1/instruct.txt new file mode 100644 index 0000000..e69de29 diff --git a/skoolos.py b/skoolos.py index ad7491b..704cef6 100644 --- a/skoolos.py +++ b/skoolos.py @@ -121,7 +121,7 @@ def chooseClassStudent(student): def classOptionsStudent(student, course): student.viewClass(course) student.getAssignments(course, 100) - choices = ["Save","Back","Exit SkoolOS"] + choices = ["Save","Submit assignment","Back","Exit SkoolOS"] options = [ { 'type': 'list', @@ -143,6 +143,33 @@ def classOptionsStudent(student, course): student.exitCLI() #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 @@ -166,6 +193,8 @@ def teacherCLI(user, password): EXIT = makeClassTeacher(teacher) #selected a class else: + #Pull confirmed students directory + teacher.getStudents(course) option = classOptionsTeacher(teacher, course) if(option == '1'): EXIT = addStudentsTeacher(teacher, course) @@ -362,13 +391,30 @@ 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 ############################################################################################################################################ From 3663fd1c903b9647d3248e4c9fd9b47823db24d9 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 19:52:31 -0400 Subject: [PATCH 06/10] students fix --- CLI/student.py | 128 +++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 68 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index f587230..d0e6b23 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -14,28 +14,22 @@ import datetime # get teacher info from api 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 + "/" r = requests.get(url=URL, auth=(ion_user, password)) if (r.status_code == 200): data = r.json() return data - elif r.status_code == 404: + elif (r.status_code == 404): return None print("Make new account!") - elif r.status_code == 403: + elif (r.status_code == 403): return None print("Invalid username/password") else: return None 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): """ Sends a GET request to the URL @@ -43,10 +37,9 @@ def getDB(user, pwd, url): """ r = requests.get(url=url, auth=(user, pwd)) 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): """ Sends a PATCH request to the URL @@ -58,7 +51,7 @@ def patchDB(user, pwd, data, url): 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): """ Sends a POST request to the URL @@ -70,7 +63,7 @@ def postDB(user, pwd, data, url): 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): """ Sends a PUT request to the URL @@ -82,7 +75,7 @@ def putDB(user, pwd, data, url): 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): """ Sends a DELETE request to the URL @@ -94,10 +87,6 @@ def delDB(user, pwd, url): def command(command): - """ - Runs a shell command - :param command: shell command - """ ar = [] command = command.split(" ") for c in command: @@ -116,10 +105,6 @@ class Student: def __init__(self, data, password): # teacher info already stored in API # intitialze fields after GET request - """ - Initializes a Student with data from the api - :param data: api data - """ self.git = data['git'] self.username = data['ion_user'] 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.repo = data['repo'] - if os.path.isdir(self.username) == False: - if self.repo == "": + if (os.path.isdir(self.username) == False): + if (self.repo == ""): user = self.git pwd = input("Enter Github password: ") # 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) def getClasses(self): - """ - Gets a lists of classes the student is enrolled in - """ classes = self.classes for c in classes: print(c['name']) - def getAssignments(self, span): - """ - Gets a list of assignments the student has - :param span: time span to check - """ + def getAssignments(self, course, span): span = datetime.timedelta(span, 0) classes = self.classes for c in classes: @@ -217,7 +195,7 @@ class Student: diff = now - due zero = datetime.timedelta(0, 0) # 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)) except Exception as e: @@ -226,9 +204,6 @@ class Student: # update API and Github, all assignments / classes def update(self): - """ - Updates the api, github, and all assignments and classes with new information - """ cdir = os.getcwd() os.chdir(self.username) command("git checkout master") @@ -251,11 +226,7 @@ class Student: # updates 1 class, does not switch to master def updateClass(self, course): - """ - Updates a class with new information - :param course: class name in the format _ - """ - if (course in self.sclass) == False: + if ((course in self.sclass) == False): print("Class not found") return cdir = os.getcwd() @@ -270,20 +241,16 @@ class Student: # add classes from 'new' field 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)) if ((cid in self.snew) == False or (self.username in data['confirmed'])): print("Already enrolled in this class.") 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.") return None - # add class teacher as collaborator to student repo + # add class teacher as cocllaborator to student repo print(os.getcwd()) pwd = input("Enter Github password: ") 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) # push to git, start at master - # os.chdir(self.username) + #os.chdir(self.username) command("git checkout master") command("git branch " + data['name']) command("git commit -m initial") @@ -325,7 +292,7 @@ class Student: user = self.git self.classes.append(data) - if len(self.sclass) == 0: + if (len(self.sclass) == 0): self.sclass = data['name'] else: self.sclass = self.sclass + "," + str(data['name']) @@ -334,7 +301,7 @@ class Student: snew = "" 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] # recreate sclass field, using ids for c in self.new: @@ -354,12 +321,46 @@ class Student: print(patchDB(self.username, self.password,data, self.url)) 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): - """ - Sets the current git branch to view each class in courses - :param courses: a list of classes - :return: - """ self.update() cdir = os.getcwd() os.chdir(self.username) @@ -374,20 +375,11 @@ class Student: return def exitCLI(self): - """ - Exits the cli - """ print(os.getcwd()) self.update() command("git checkout master") def submit(self, course, assignment): - """ - Submits an assignment - :param course: the class the assignment belongs to - :param assignment: the assignment - :return: - """ cdir = os.getcwd() os.chdir(self.username) print(os.getcwd()) @@ -402,7 +394,7 @@ class Student: inclass = True oname = a + "_" + course break - if inclass == False: + if (inclass == False): print(assignment + " not an assignment of " + course) command('git checkout master') os.chdir(cdir) @@ -414,7 +406,7 @@ class Student: command("git tag " + assignment + "-final") command("git push -u origin " + course + " --tags") command('git checkout master') - self.completed = oname + "," + self.completed + self.completed = assignment + "," + self.completed data = { 'completed': self.completed } From cbe66098165ad74939a84e4129db9471dd66e848 Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 19:55:24 -0400 Subject: [PATCH 07/10] redocumented skoolos.py --- skoolos.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/skoolos.py b/skoolos.py index 68afc8c..8779f15 100644 --- a/skoolos.py +++ b/skoolos.py @@ -440,30 +440,70 @@ def getUser(ion_user, password, utype): def patchDB(USER, PWD, url, 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("PATH:" + str(r.status_code)) return r.json() def getDB(USER, PWD, url): + """ + Sends a GET 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.get(url=url, auth=(USER, PWD)) print("GET:" + str(r.status_code)) return r.json() def postDB(USER, PWD, url, 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)) return r.json() def putDB(USER, PWD, url, 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() def delDB(USER, PWD, url): + """ + Sends a DELETE 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.delete(url=url, auth=(USER, PWD)) print("DELETE:" + str(r.status_code)) return None From 65a35b540b3c8534ce8527e5ef44790d9f83d82d Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 20:08:06 -0400 Subject: [PATCH 08/10] fixed skoolos.py documentation and redocumented student.py --- CLI/student.py | 33 ++++++++++++++++++++++++--------- skoolos.py | 2 -- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index d0e6b23..285b001 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -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)) diff --git a/skoolos.py b/skoolos.py index 6f953e8..a5dfb83 100644 --- a/skoolos.py +++ b/skoolos.py @@ -505,7 +505,6 @@ def getDB(USER, PWD, url): :param USER: username :param PWD: password :param url: URL for request - :param data: data to request :return: json request response """ r = requests.get(url=url, auth=(USER, PWD)) @@ -547,7 +546,6 @@ def delDB(USER, PWD, url): :param USER: username :param PWD: password :param url: URL for request - :param data: data to request :return: json request response """ r = requests.delete(url=url, auth=(USER, PWD)) From 925818c49c547deca71477c220eca8d232649d5f Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 20:18:25 -0400 Subject: [PATCH 09/10] finished cli --- CLI/teacher.py | 11 +++++++++-- eharris1/History12_eharris1/README.md | 0 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 eharris1/History12_eharris1/README.md diff --git a/CLI/teacher.py b/CLI/teacher.py index cde7e7f..a6d94a0 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -96,7 +96,7 @@ def putDB(user, pwd, data, url): :param user: a string :param password: a string :param url: URL for request - """ + """ r = requests.put(url=url, data=data, auth=(user, pwd)) print("PUT:" + str(r.status_code)) return r.json() @@ -152,6 +152,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") @@ -727,7 +734,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'] diff --git a/eharris1/History12_eharris1/README.md b/eharris1/History12_eharris1/README.md new file mode 100644 index 0000000..e69de29 From 9d02b3dd3ba3ab3ee0b31a56c902448637a304ee Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 20:21:30 -0400 Subject: [PATCH 10/10] redocumented teacher.py --- CLI/teacher.py | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/CLI/teacher.py b/CLI/teacher.py index cde7e7f..116662d 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -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))