DB requests uupdates

This commit is contained in:
Raffu Khondaker 2020-06-16 18:03:07 -04:00
parent 4b024f3932
commit 9fec8ad95d
14 changed files with 190 additions and 158 deletions

View File

@ -13,9 +13,9 @@ import datetime
# git clone student directory ==> <student-id>/classes/assignments # git clone student directory ==> <student-id>/classes/assignments
# get teacher info from api # get teacher info from api
def getStudent(ion_user): def getStudent(ion_user, password):
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
r = requests.get(url=URL, auth=('raffukhondaker', 'hackgroup1')) r = requests.get(url=URL, auth=(ion_user, password))
if (r.status_code == 200): if (r.status_code == 200):
data = r.json() data = r.json()
return data return data
@ -30,33 +30,60 @@ def getStudent(ion_user):
print(r.status_code) print(r.status_code)
#makes a GET request to given url, returns dict #makes a GET request to given url, returns dict
def getDB(url): def getDB(user, pwd, 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=(user, pwd))
print("GET:" + str(r.status_code)) print("GET:" + str(r.status_code))
return (r.json())
#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'))
print("PATCH:" + str(r.status_code))
return(r.json()) return(r.json())
#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 url: URL for request
"""
r = requests.patch(url=url, data=data, auth=(user, pwd))
print("PATCH:" + str(r.status_code))
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): def postDB(user, pwd, data, url):
r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) """
Sends a POST request to the URL
:param data:
:param url: URL for request
"""
r = requests.post(url=url, data=data, auth=(user, pwd))
print("POST:" + str(r.status_code)) print("POST:" + str(r.status_code))
return (r.json()) return r.json()
#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): def putDB(user, pwd, data, url):
r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) """
Sends a PUT request to the URL
:param data:
:param url: URL for request
"""
r = requests.put(url=url, data=data, auth=(user, pwd))
print("PUT:" + str(r.status_code)) print("PUT:" + str(r.status_code))
return (r.json()) return r.json()
#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): def delDB(user, pwd, url):
r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1')) """
Sends a DELETE request to the URL
:param url: URL for request
"""
r = requests.delete(url=url, auth=(user, pwd))
print("DELETE:" + str(r.status_code)) print("DELETE:" + str(r.status_code))
return None
def command(command): def command(command):

View File

@ -26,14 +26,16 @@ from datetime import datetime
# git clone student directory ==> <student-id>/classes/assignments # git clone student directory ==> <student-id>/classes/assignments
# get teacher info from api # get teacher info from api
def getTeacher(ion_user): def getTeacher(ion_user, password):
""" """
Gets information about a teacher from the api Gets information about a teacher from the api
:param ion_user: a teacher :param ion_user: a teacher
:param password: a string
:return: teacher information or error :return: teacher information or error
""" """
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/" URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
r = requests.get(url=URL, auth=('raffukhondaker', 'hackgroup1')) r = requests.get(url=URL, auth=(ion_user,password))
print(r.json())
if r.status_code == 200: if r.status_code == 200:
data = r.json() data = r.json()
return data return data
@ -48,58 +50,67 @@ def getTeacher(ion_user):
print(r.status_code) print(r.status_code)
#makes a GET request to given url, returns dict #makes a GET request to given url, returns dict
def getDB(url): def getDB(user, pwd, url):
""" """
Sends a GET request to the URL Sends a GET request to the URL
:param user: a string
:param password: a string
:param url: URL for request :param url: URL for request
""" """
r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1')) r = requests.get(url=url, auth=(user, pwd))
print("GET:" + str(r.status_code)) print("GET:" + str(r.status_code))
return(r.json()) return(r.json())
#makes a PATCH (updates instance) request to given url, returns dict #makes a PATCH (updates instance) request to given url, returns dict
def patchDB(data, url): def patchDB(user, pwd, data, url):
""" """
Sends a PATCH request to the URL Sends a PATCH request to the URL
:param data: :param data:
:param user: a string
:param password: a string
:param url: URL for request :param url: URL for request
""" """
r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) r = requests.patch(url=url, data=data, auth=(user, pwd))
print("PATCH:" + str(r.status_code)) 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): def postDB(user, pwd, data, url):
""" """
Sends a POST request to the URL Sends a POST request to the URL
:param data: :param data:
:param user: a string
:param password: a string
:param url: URL for request :param url: URL for request
""" """
r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) r = requests.post(url=url, data=data, auth=(user, pwd))
print("POST:" + str(r.status_code)) print("POST:" + str(r.status_code))
return r.json() return r.json()
#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): def putDB(user, pwd, data, url):
""" """
Sends a PUT request to the URL Sends a PUT request to the URL
:param data: :param user: a string
:param password: a string
:param url: URL for request :param url: URL for request
""" """
r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) r = requests.put(url=url, data=data, auth=(user, pwd))
print("PUT:" + str(r.status_code)) print("PUT:" + str(r.status_code))
return r.json() return r.json()
#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): def delDB(user, pwd, url):
""" """
Sends a DELETE request to the URL Sends a DELETE request to the URL
:param user: a string
:param password: a string
:param url: URL for request :param url: URL for request
""" """
r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1')) r = requests.delete(url=url, auth=(user, pwd))
print("DELETE:" + str(r.status_code)) print("DELETE:" + str(r.status_code))
return None return None
@ -123,7 +134,7 @@ def command(command):
# public methods: deleteClass, makeClass, update # public methods: deleteClass, makeClass, update
class Teacher: class Teacher:
def __init__(self, data): def __init__(self, data, password):
# teacher info already stored in API # teacher info already stored in API
# intitialze fields after GET request # intitialze fields after GET request
""" """
@ -134,6 +145,7 @@ class Teacher:
self.username = data['ion_user'] self.username = data['ion_user']
self.url = "http://127.0.0.1:8000/api/teachers/" + self.username + "/" self.url = "http://127.0.0.1:8000/api/teachers/" + self.username + "/"
self.id = data['user'] self.id = data['user']
self.password = password
# classes in id form (Example: 4,5) # classes in id form (Example: 4,5)
# array # array
@ -218,15 +230,22 @@ class Teacher:
return return
if self.checkClass(path): if self.checkClass(path):
cpath = self.username + "/" + cname cpath = self.username + "/" + cname
subject = cname.split("_")[0]
period = int(input("Enter period: "))
while(not (type(period) is int and period >= 0)):
print("Incorrect format")
period = int(input("Enter period: "))
data = { data = {
"name": cname, "name": cname,
"repo": "", "repo": "",
"path": cpath, "path": cpath,
"subject": subject,
"period":period,
"teacher": self.username, "teacher": self.username,
"owner": self.id "owner": self.id
} }
# make class instance in db # make class instance in db
postDB(data, 'http://127.0.0.1:8000/api/classes/') postDB(self.username, self.password, data, 'http://127.0.0.1:8000/api/classes/')
time.sleep(1) time.sleep(1)
self.classes.append(cname) self.classes.append(cname)
# add to instance # add to instance
@ -235,7 +254,7 @@ class Teacher:
'classes': self.classes 'classes': self.classes
} }
print(self.classes) print(self.classes)
print(patchDB(data, 'http://127.0.0.1:8000/api/teachers/' + self.username + "/")) print(patchDB(self.username, self.password, data, 'http://127.0.0.1:8000/api/teachers/' + self.username + "/"))
# make a new class from scratch # make a new class from scratch
# subject: string, assignments: list # subject: string, assignments: list
@ -248,7 +267,7 @@ class Teacher:
# check if class exists # check if class exists
path = self.username + "/" + cname path = self.username + "/" + cname
isclass = False isclass = False
acourses = getDB("http://127.0.0.1:8000/api/classes/")['results'] acourses = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/")['results']
for c in acourses: for c in acourses:
if c['name'] == cname: if c['name'] == cname:
isclass = True isclass = True
@ -300,7 +319,7 @@ class Teacher:
# 'classes':self.classes, # 'classes':self.classes,
# } # }
# print(patchDB(data, self.url)) # print(patchDB(data, self.url))
delDB("http://127.0.0.1:8000/api/classes/" + cname + "/") delDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + cname + "/")
break break
# remove locally # remove locally
@ -318,7 +337,7 @@ class Teacher:
:return: True if student exists, False otherwise :return: True if student exists, False otherwise
""" """
r = requests.get(url="http://127.0.0.1:8000/api/students/" + student + "/", r = requests.get(url="http://127.0.0.1:8000/api/students/" + student + "/",
auth=('raffukhondaker', 'hackgroup1')) auth=(self.username, self.password))
if r.status_code != 200: if r.status_code != 200:
return False return False
return True return True
@ -333,7 +352,7 @@ class Teacher:
if not self.isStudent(sname): if not self.isStudent(sname):
print(sname + " does not exist.") print(sname + " does not exist.")
return False return False
course = getDB("http://127.0.0.1:8000/api/classes/" + cname) course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + cname)
if sname in str(course['unconfirmed']): if sname in str(course['unconfirmed']):
print(sname + " already requested.") print(sname + " already requested.")
return True return True
@ -341,7 +360,7 @@ class Teacher:
print(sname + " already enrolled.") print(sname + " already enrolled.")
return False return False
student = getDB("http://127.0.0.1:8000/api/students/" + sname) student = getDB(self.username, self.password, "http://127.0.0.1:8000/api/students/" + sname)
try: try:
if student['added_to'] == "": if student['added_to'] == "":
student['added_to'] = course['name'] student['added_to'] = course['name']
@ -354,8 +373,8 @@ class Teacher:
data = { data = {
'added_to': student['added_to'], 'added_to': student['added_to'],
} }
student = patchDB(data, "http://localhost:8000/api/students/" + student['ion_user'] + "/") student = patchDB(self.username, self.password, data, "http://localhost:8000/api/students/" + student['ion_user'] + "/")
student = getDB("http://localhost:8000/api/students/" + sname + "/") student = getDB(self.username, self.password, "http://localhost:8000/api/students/" + sname + "/")
if not course['unconfirmed']: if not course['unconfirmed']:
course['unconfirmed'] = student['ion_user'] course['unconfirmed'] = student['ion_user']
else: else:
@ -364,7 +383,7 @@ class Teacher:
"unconfirmed": course['unconfirmed'] "unconfirmed": course['unconfirmed']
} }
print(cinfo) print(cinfo)
patchDB(cinfo, "http://localhost:8000/api/classes/" + course['name'] + "/") patchDB(self.username, self.password, cinfo, "http://localhost:8000/api/classes/" + course['name'] + "/")
return True return True
# Student should have confirmed on their endd, but class had not been updated yet # Student should have confirmed on their endd, but class had not been updated yet
@ -380,8 +399,8 @@ class Teacher:
print(sname + " does not exist.") print(sname + " does not exist.")
return False return False
student = getDB("http://127.0.0.1:8000/api/students/" + sname) student = getDB(self.username, self.password, "http://127.0.0.1:8000/api/students/" + sname)
course = getDB("http://127.0.0.1:8000/api/classes/" + cname) course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + cname)
if (os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or ( if (os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or (
student['ion_user'] in course['confirmed']) == True): student['ion_user'] in course['confirmed']) == True):
@ -435,7 +454,7 @@ class Teacher:
"confirmed": course["confirmed"], "confirmed": course["confirmed"],
"unconfirmed": course['unconfirmed'] "unconfirmed": course['unconfirmed']
} }
print(putDB(course, "http://localhost:8000/api/classes/" + course['name'] + "/")) print(putDB(self.username, self.password, course, "http://localhost:8000/api/classes/" + course['name'] + "/"))
return True return True
# goes through list of studennts, tries to add, then request, return unconfirmed students # goes through list of studennts, tries to add, then request, return unconfirmed students
@ -494,7 +513,7 @@ class Teacher:
print("Due-date format is incorrect") print("Due-date format is incorrect")
return False return False
course = getDB("http://127.0.0.1:8000/api/classes/" + course) course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course)
if aname in str(course['assignments']): if aname in str(course['assignments']):
print("Assignment name already taken.") print("Assignment name already taken.")
return False return False
@ -525,22 +544,23 @@ class Teacher:
print(st + " already has assignment") print(st + " already has assignment")
# check if assignment already exists # check if assignment already exists
r = requests.get(url='http://127.0.0.1:8000/api/assignments/' + aname, auth=('raffukhondaker', 'hackgroup1')) r = requests.get(url='http://127.0.0.1:8000/api/assignments/' + aname, auth=(self.username, self.password))
if r.status_code != 200: if r.status_code != 200:
ass = { ass = {
'name': oname, 'name': oname,
'path': path, 'path': path,
'classes': course['name'], 'classes': course['name'],
'teacher': self.username, 'teacher': self.username,
'due_date': due 'due_date': due,
'owner':self.id
} }
postDB(ass, 'http://127.0.0.1:8000/api/assignments/') postDB(self.username, self.password, ass, 'http://127.0.0.1:8000/api/assignments/')
course['assignments'].append(oname) course['assignments'].append(oname)
cinfo = { cinfo = {
"assignments": course['assignments'], "assignments": course['assignments'],
} }
print(patchDB(cinfo, "http://127.0.0.1:8000/api/classes/" + course['name'] + "/")) print(patchDB(self.username, self.password, cinfo, "http://127.0.0.1:8000/api/classes/" + course['name'] + "/"))
return True return True
else: else:
print("Assignment already addedd") print("Assignment already addedd")
@ -561,12 +581,12 @@ class Teacher:
d = { d = {
'due_date': due, 'due_date': due,
} }
print(patchDB(d, 'http://localhost:8000/api/assignments/' + oname + "/")) print(patchDB(self.username, self.password, d, 'http://localhost:8000/api/assignments/' + oname + "/"))
print("Due-date changed " + due) print("Due-date changed " + due)
except: except:
print("Due-date is the same") print("Due-date is the same")
input() input()
course = getDB("http://127.0.0.1:8000/api/classes/" + course) course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course)
slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name']) slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name'])
cdir = os.getcwd() cdir = os.getcwd()
for st in slist: for st in slist:
@ -597,7 +617,7 @@ class Teacher:
os.chdir(cdir) os.chdir(cdir)
def getCommits(self, student, course, commits): def getCommits(self, student, course, commits):
course = getDB("http://127.0.0.1:8000/api/classes/" + course) course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course)
try: try:
if not (student in course['confirmed']): if not (student in course['confirmed']):
print("Student not in class") print("Student not in class")
@ -645,7 +665,7 @@ class Teacher:
:param course: the course :param course: the course
:param commits: commits the CLI has made for the assignment :param commits: commits the CLI has made for the assignment
""" """
course = getDB("http://127.0.0.1:8000/api/classes/" + course + "/") course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course + "/")
ar = self.getCommits(student, course['name'], commits) ar = self.getCommits(student, course['name'], commits)
commit = ar[len(ar) - 1][0] commit = ar[len(ar) - 1][0]
start = "" start = ""
@ -670,7 +690,7 @@ class Teacher:
def afterSubmit(self, course, assignment, student): def afterSubmit(self, course, assignment, student):
assignment = getDB("http://127.0.0.1:8000/api/assignments/" + assignment) assignment = getDB(self.username, self.password, "http://127.0.0.1:8000/api/assignments/" + assignment)
# assignment = { # assignment = {
# 'name': assignment, # 'name': assignment,
# 'due_date': "2020-04-11 16:58:33.383124", # 'due_date': "2020-04-11 16:58:33.383124",
@ -705,8 +725,9 @@ class Teacher:
print("heheheh") print("heheheh")
# data = getTeacher("eharris1") data = getTeacher("eharris1","hackgroup1")
# t = Teacher(data) print(data)
t = Teacher(data, "hackgroup1")
# t.makeClass("APLit_eharris1") # t.makeClass("APLit_eharris1")
# t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124') # t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124')
# ar = ['2022rkhondak','2022inafi','2023rumareti'] # ar = ['2022rkhondak','2022inafi','2023rumareti']

View File

@ -34,7 +34,7 @@ class ClassSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Class model = Class
# fields = ['url','name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed','owner'] # fields = ['url','name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed','owner']
fields = ['name', 'repo','path','assignments',"teacher","default_file", 'confirmed', 'unconfirmed','owner'] fields = ['name', 'repo','path','subject','period','assignments',"teacher","default_file", 'confirmed', 'unconfirmed','owner']
class StudentSerializer(serializers.ModelSerializer): class StudentSerializer(serializers.ModelSerializer):
# Class = ClassSerializer(many=True, read_only=True,allow_null=True) # Class = ClassSerializer(many=True, read_only=True,allow_null=True)

View File

@ -1,7 +0,0 @@
kskskksks
kskskksks
kskskksks
kskskksks
kskskksks
kskskksks
kskskksks

View File

@ -35,7 +35,9 @@ def main():
print("╚═════╝░╚═╝░░╚═╝░╚════╝░░╚════╝░╚══════╝  ░╚════╝░╚═════╝░") print("╚═════╝░╚═╝░░╚═╝░╚════╝░░╚════╝░╚══════╝  ░╚════╝░╚═════╝░")
print("") print("")
if not (os.path.exists(".sprofile") or os.path.exists(".tprofile")): profiles = os.listdir()
if not ("profile" in str(profiles)):
try: try:
URL = "http://127.0.0.1:8000/api/" URL = "http://127.0.0.1:8000/api/"
r = requests.get(url = URL) r = requests.get(url = URL)
@ -60,6 +62,7 @@ def main():
info.append(d) info.append(d)
users.append(str(count) + ") " + d['username']) users.append(str(count) + ") " + d['username'])
count = count+1 count = count+1
users.append(str(count) + ") Make new user")
user = [ user = [
{ {
'type': 'list', 'type': 'list',
@ -69,6 +72,9 @@ def main():
}, },
] ]
u = int(prompt(user)['user'].split(")")[0]) -1 u = int(prompt(user)['user'].split(")")[0]) -1
if(u+1 == count):
authenticate()
return
data = info[u] data = info[u]
PWD = data['password'] PWD = data['password']
USER = data['username'] USER = data['username']
@ -78,7 +84,7 @@ def main():
else: else:
teacherCLI(USER, PWD) teacherCLI(USER, PWD)
################################################ STUDENT METHODS #################################################################################################### STUDENT METHODS
def studentCLI(user, password): def studentCLI(user, password):
from CLI import student from CLI import student
@ -88,6 +94,8 @@ def studentCLI(user, password):
EXIT = False EXIT = False
while(not EXIT): while(not EXIT):
course = chooseClassStudent(student) course = chooseClassStudent(student)
if(course == "Exit SkoolOS"):
return
EXIT = classOptionsStudent(student, course) EXIT = classOptionsStudent(student, course)
#return class #return class
@ -137,7 +145,37 @@ def classOptionsStudent(student, course):
return True return True
################################################ TEACHER METHODS #################################################################################################### TEACHER METHODS
def teacherCLI(user, password):
from CLI import teacher
data = getUser(user, password, 'teacher')
print(data)
teacher = teacher.Teacher(data)
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): def chooseGeneralTeacher(teacher):
carray = [] carray = []
for c in teacher.classes: for c in teacher.classes:
@ -192,7 +230,7 @@ def makeClassTeacher(teacher):
teacher.reqAddStudentList(students, cname) teacher.reqAddStudentList(students, cname)
return False return False
def classOptionsTeacher(teacher, course): def classOptionsTeacher(teacher, course, password):
print("Class: " + course) print("Class: " + course)
unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed']
for s in unconf: for s in unconf:
@ -254,7 +292,7 @@ def addStudentsTeacher(teacher, course):
def addAssignmentTeacher(teacher, course): def addAssignmentTeacher(teacher, course):
nlist = os.listdir(teacher.username + "/" + course) nlist = os.listdir(teacher.username + "/" + course)
alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] alist = getDB(teacher.username, "http://localhost:8000/api/classes/" + course)['assignments']
print(nlist) print(nlist)
tlist = [] tlist = []
b = True b = True
@ -274,7 +312,8 @@ def addAssignmentTeacher(teacher, course):
nlist = tlist nlist = tlist
if(len(nlist) == 0): if(len(nlist) == 0):
print("No new assignments found") print("No new assignments found")
sys.exit(0) print("To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder")
return False
questions = [ questions = [
{ {
'type': 'list', 'type': 'list',
@ -299,86 +338,37 @@ def addAssignmentTeacher(teacher, course):
due = input("Enter due date (Example: 2020-08-11 16:58): ") due = input("Enter due date (Example: 2020-08-11 16:58): ")
due = due + ":33.383124" due = due + ":33.383124"
teacher.addAssignment(apath, course, due) teacher.addAssignment(apath, course, due)
return False
def teacherCLI(user, password): def viewStudentsTeacher(teacher, course):
from CLI import teacher data = getDB("http://127.0.0.1:8000/api/classes/" + course)
data = getUser(user, password, 'teacher') students = data["confirmed"]
print(data) unconf = data['unconfirmed']
teacher = teacher.Teacher(data) print("Studented in class: ")
EXIT = False for s in students:
# 1. make a class print(s)
# 2. add studeents to an existing class print("Requsted Students: ")
# 3. Get progress logs on a student for s in unconf:
# 2. make an assignment for a class print(s)
# 3. view student submissions for an assignment student = input("View student (Enter student's ion username): ")
while(not EXIT): while((not student in str(data['confirmed'])) or (not student in str(data['unconfirmed']))):
#Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit" print("Student not affiliated with class")
course = chooseGeneralTeacher(teacher) student = input("View student ('N' to exit): ")
if course == "Exit SkoolOS": if student == 'N':
EXIT = True return True
if course == "Make New Class": print(getDB("http://127.0.0.1:8000/api/students/" + student + "/"))
EXIT = makeClassTeacher(teacher)
#selected a class
else:
option = classOptionsTeacher(teacher, course)
if(option == '1'):
EXIT = addStudentsTeacher(teacher, course)
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)
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
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)
###################################################################### ############################################################################################################################################
def getUser(ion_user, password, utype): def getUser(ion_user, password, utype):
if('student' in utype): if('student' in utype):
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" URL = "http://127.0.0.1:8000/api/students/" + USER + "/"
else: else:
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/" URL = "http://127.0.0.1:8000/api/teachers/" + USER + "/"
print(URL)
r = requests.get(url = URL, auth=(ion_user,password)) r = requests.get(url = URL, auth=(ion_user,password))
print(r.json()) print(r.json())
if(r.status_code == 200): if(r.status_code == 200):
@ -394,28 +384,29 @@ def getUser(ion_user, password, utype):
else: else:
print(r.status_code) print(r.status_code)
return None return None
def patchDB(data, url):
def patchDB(USER, PWD, url, data):
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)) print("PATH:" + str(r.status_code))
return(r.json()) return(r.json())
def getDB(url): def getDB(USER, PWD, url):
r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) r = requests.get(url = url, auth=(USER,PWD))
print("GET:" + str(r.status_code)) print("GET:" + str(r.status_code))
return(r.json()) return(r.json())
def postDB(data, url): def postDB(USER, PWD, url, data):
r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) r = requests.post(url = url, data=data, auth=(USER,PWD))
print("POST:" + str(r.status_code)) print("POST:" + str(r.status_code))
return(r.json()) return(r.json())
def putDB(data, url): def putDB(USER, PWD, url, data):
r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) r = requests.put(url = url, data=data, auth=(USER,PWD))
print("PUT:" + str(r.status_code)) print("PUT:" + str(r.status_code))
return(r.json()) return(r.json())
def delDB(url): def delDB(USER, PWD, url):
r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) r = requests.delete(url = url, auth=(USER,PWD))
print("DELETE:" + str(r.status_code)) print("DELETE:" + str(r.status_code))
return None return None
@ -454,10 +445,7 @@ def authenticate():
#Linux: chromdriver-linux #Linux: chromdriver-linux
#Macos: chromdriver-mac #Macos: chromdriver-mac
#Windows: chromdriver.exe #Windows: chromdriver.exe
if('CLI' in os.getcwd()): path = os.path.join(os.getcwd(),'chromedriver','chromedriver-mac')
path = os.path.join(os.getcwd(), '../','chromedriver-mac')
else:
path = os.path.join(os.getcwd(), 'chromedriver-mac')
browser = webdriver.Chrome(path) browser = webdriver.Chrome(path)
@ -516,7 +504,8 @@ def authenticate():
'is_student':is_student, 'is_student':is_student,
'password':pwd, 'password':pwd,
} }
profileFile = open(".sprofile", "w") fname = "." + username + "profile"
profileFile = open(fname, "w")
profileFile.write(json.dumps(profile)) profileFile.write(json.dumps(profile))
profileFile.close() profileFile.close()
@ -530,11 +519,13 @@ def authenticate():
'is_student':is_student, 'is_student':is_student,
'password':pwd, 'password':pwd,
} }
profileFile = open(".tprofile", "w") fname = "." + username + "profile"
profileFile = open(fname, "w")
profileFile.write(json.dumps(profile)) profileFile.write(json.dumps(profile))
profileFile.close() profileFile.close()
sys.exit sys.exit(0)
def create_server(): def create_server():
port = 8000 port = 8000