diff --git a/CLI/student.py b/CLI/student.py index 2d494a2..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 + "/" @@ -127,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(",") @@ -165,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 @@ -190,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: @@ -216,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: @@ -225,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") @@ -250,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() @@ -269,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'] @@ -302,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") @@ -324,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']) @@ -333,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: @@ -353,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) @@ -373,34 +375,26 @@ 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()) 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: + if (inclass == False): print(assignment + " not an assignment of " + course) command('git checkout master') os.chdir(cdir) @@ -412,6 +406,11 @@ class Student: command("git tag " + assignment + "-final") command("git push -u origin " + course + " --tags") command('git checkout master') + self.completed = assignment + "," + self.completed + data = { + 'completed': self.completed + } + patchDB(self.username, self.password, data, self.url) os.chdir(cdir) diff --git a/CLI/teacher.py b/CLI/teacher.py index 3281083..cde7e7f 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 8779f15..6f953e8 100644 --- a/skoolos.py +++ b/skoolos.py @@ -145,8 +145,8 @@ def classOptionsStudent(student, 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","Submit assignment","Back","Exit SkoolOS"] options = [ { 'type': 'list', @@ -168,6 +168,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 @@ -196,6 +223,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) @@ -398,13 +427,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 ############################################################################################################################################