Merge branch 'development' of https://github.com/rushilwiz/SkoolOs into development

Merged working with local
.
This commit is contained in:
Rushil Umaretiya 2020-06-13 06:46:51 -04:00
commit 511b249b47
22 changed files with 252 additions and 87 deletions

1
.profile Normal file
View File

@ -0,0 +1 @@
{'absences': 2, 'address': None, 'counselor': {'first_name': 'Sean', 'full_name': 'Sean Burke', 'id': 37, 'last_name': 'Burke', 'url': 'https://ion.tjhsst.edu/api/profile/37', 'user_type': 'counselor', 'username': 'SPBurke'}, 'display_name': 'Raffu Khondaker', 'emails': [], 'first_name': 'Raffu', 'full_name': 'Raffu Khondaker', 'grade': {'name': 'sophomore', 'number': 10}, 'graduation_year': 2022, 'id': 36508, 'ion_username': '2022rkhondak', 'is_announcements_admin': False, 'is_eighth_admin': False, 'is_student': True, 'is_teacher': False, 'last_name': 'Khondaker', 'middle_name': 'Al', 'nickname': '', 'phones': [], 'picture': 'https://ion.tjhsst.edu/api/profile/36508/picture', 'sex': 'Male', 'short_name': 'Raffu', 'title': None, 'tj_email': '2022rkhondak@tjhsst.edu', 'user_type': 'student', 'websites': []}

0
CLI/.profile Normal file
View File

View File

@ -1,2 +0,0 @@
import os
os.spawnl(os.P_DETACH, 'some_long_running_command')

View File

@ -14,7 +14,7 @@
</head>
<body>
<div class="d-flex align-items-center justify-content-center" style="height: 100vh">
<a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F&scope=read&state=5EVwgQRAWaQngvshhCbYiTwC9Rpi7N" title="Ion" class="border border-dark p-3 btn btn-lg mx-auto" style="box-shadow: 5px 10px;">
<a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F&scope=read&state=81xYFv6S9CLi7laXQ64gJWskDJUMMb" title="Ion" class="border border-dark p-3 btn btn-lg mx-auto" style="box-shadow: 5px 10px;">
<img src="https://ion.tjhsst.edu/static/img/favicon.png">
Sign in with Ion
</a>

View File

@ -1,21 +0,0 @@
asgiref==3.2.7
certifi==2020.4.5.1
chardet==3.0.4
click==7.1.2
Django==3.0.7
django-cors-middleware==1.5.0
django-oauth-toolkit==1.3.2
djangorestframework==3.11.0
idna==2.9
oauthlib==3.1.0
prompt-toolkit==1.0.14
Pygments==2.6.1
PyInquirer==1.0.3
pytz==2020.1
regex==2020.5.14
requests==2.23.0
selenium==3.141.0
six==1.15.0
sqlparse==0.3.1
urllib3==1.25.9
wcwidth==0.2.3

View File

@ -7,6 +7,7 @@ import json
import shutil
import time
import pyperclip
import datetime
#git clone student directory ==> <student-id>/classes/assignments
@ -147,11 +148,38 @@ class Student:
print(putDB(data, self.url))
print("Synced to " + self.username)
def getClasses(self):
classes = self.classes
for c in classes:
print(c['name'])
def getAssignments(self, course, span):
span = datetime.timedelta(span, 0)
classes = self.classes
for c in classes:
print(c['name'])
alist = c['assignments'].split(",")
for a in alist:
ass = getDB("http://127.0.0.1:8000/api/assignments/" + a)
now = datetime.datetime.now()
try:
due = ass['due_date'].replace("T", " ").replace("Z", "")
due = datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
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):
print((now-due))
except Exception as e:
print(e)
pass
#update API and Github, all assignments / classes
def update(self):
cdir = os.getcwd()
os.chdir(self.username)
command("git checkout master")
for c in self.classes:
print("UPDATING CLASS: " + str(c['name']))
data = getDB("http://127.0.0.1:8000/api/classes/" + str(c['name']))
@ -167,6 +195,19 @@ class Student:
print("ADDING CLASS: " + str(c['name']))
self.addClass(str(c['name']))
command("git checkout master")
#updates 1 class, does not switch to master
def updateClass(self, course):
if((course in self.sclass) == False):
print("Class not found")
return
cdir = os.getcwd()
os.chdir(self.username)
command("git checkout " + course)
command("git add .")
command("git commit -m " + course)
command("git pull origin " + course)
command("git push -u origin " + course)
#class name format: <course-name>_<ion_user>
@ -347,5 +388,8 @@ class Student:
data = getStudent("2022rkhondak")
s = Student(data)
# s.viewClass("English11_eharris1")
#s.viewClass("APLit_eharris1")
#s.updateClass("APLit_eharris1")
#s.update()
s.exitCLI()

View File

@ -10,6 +10,7 @@ import http.server
import socketserver
from threading import Thread
from werkzeug.urls import url_decode
import pprint
client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6'
client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY'
@ -29,19 +30,29 @@ def main():
print("")
if not os.path.exists(".profile"):
print(76546789876545678765)
authenticate()
print(open(".profile", "r").read())
else:
print(open(".profile", "r").read())
while True:
pass
# while True:
# pass
def authenticate():
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
path = os.path.join(cdir, "chromedriver-mac")
print(path)
browser = webdriver.Chrome(path)
browser = webdriver.Safari()
web_dir = os.path.join(os.path.dirname(__file__), 'oauth')
os.chdir(web_dir)
if os.path.exists("index.html"):
@ -58,7 +69,6 @@ def authenticate():
server.daemon = True
server.start()
browser = webdriver.Chrome()
browser.get("localhost:8000/")
while "http://localhost:8000/?code" not in browser.current_url:
@ -83,18 +93,20 @@ def authenticate():
# And finally get the user's profile!
profile = requests.get("https://ion.tjhsst.edu/api/profile", headers=headers).json()
print(profile)
pprint.pprint(profile)
username = profile['ion_username']
email = profile['tj_email']
first_name = profile['first_name']
last_name = profile['last_name']
os.chdir("..")
os.chdir(cdir)
profileFile = open(".profile", "w")
profileFile.write(profile.text())
#profileFile.write(profile.text())
profileFile.write(str(profile))
profileFile.close()
# sys.exit
sys.exit
def create_server():

View File

@ -154,7 +154,7 @@ class Teacher:
if (self.checkClass(path)):
cname = path.split("/")
cname = cname[len(cname)-1]
cpath = self.username + "/" + cname[len(cname)-1]
cpath = self.username + "/" + cname
data = {
"name": cname,
"repo": "",
@ -193,7 +193,7 @@ class Teacher:
#make a new class from scratch
#subject: string, assignments: list
#class name must be: <subject>_<ion_user>
def makeClass(self, cname, assignments):
def makeClass(self, cname):
#check if class exists
path = self.username + "/" + cname
isclass = False
@ -216,7 +216,7 @@ class Teacher:
f=open(path + "/README.md", "w")
f.close()
#push to remote repo
os.chdir(path)
# os.chdir(path)
# for a in assignments:
# os.mkdir(a)
@ -280,14 +280,14 @@ class Teacher:
def reqStudent(self, sname, cname):
if(self.isStudent(sname) == False):
print(sname + " does not exist.")
return
return False
course = getDB("http://127.0.0.1:8000/api/classes/" + cname)
if(sname in course['unconfirmed']):
print (sname + " already requested.")
return
return True
if(sname in course['confirmed']):
print (sname + " alredy enrolled.")
return
return False
student = getDB("http://127.0.0.1:8000/api/students/" + sname)
try:
@ -297,7 +297,7 @@ class Teacher:
student['added_to']=student['added_to']+ "," + course['name']
except:
print(sname + " does not exist.")
return
return False
print(student['added_to'])
s={
'first_name':student["first_name"],
@ -323,31 +323,34 @@ class Teacher:
"repo": "",
"path": self.username + "/" + course['name'],
"teacher": self.username,
"assignments": "",
"assignments": course['assignments'],
"default_file": "",
"confirmed": course["confirmed"],
"unconfirmed": course['unconfirmed']
}
print(putDB(cinfo, course['url']))
return True
#Student should have confirmed on their endd, but class had not been updated yet
#git clone confirmed student repo, copy files into repo and push branch
def addStudent(self, sname, cname):
if(self.isStudent(sname) == False):
print(sname + " does not exist.")
return
return False
student = getDB("http://127.0.0.1:8000/api/students/" + sname)
course = getDB("http://127.0.0.1:8000/api/classes/" + cname)
if((student['ion_user'] in course['unconfirmed']) == False):
print("Student has not been requested to join yet.")
return
if((cname in student['added_to']) == True or (cname in student['classes']) == False):
print("Student has not confirmed class yet")
return
if(os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or (student['ion_user'] in course['confirmed']) == True):
print("Student already added to class")
print(student['ion_user'] + " already added to class")
return True
if((cname in student['added_to']) == True or (cname in student['classes']) == False):
print(student['ion_user']+ " has not confirmed class yet")
return False
if((student['ion_user'] in course['unconfirmed']) == False):
print(course['unconfirmed'])
print(student['ion_user']+" has not been requested to join yet.")
return False
#git clone and make student/class directories
cdir = os.getcwd()
@ -362,67 +365,97 @@ class Teacher:
os.chdir(cdir)
#push to git
copy_tree(cpath, path + "/" + student['ion_user'])
os.chdir(spath)
command('git checkout ' + cname)
command('git pull origin ' + cname)
os.chdir(cdir)
copy_tree(cpath, path + "/" + student['ion_user'])
os.chdir(spath)
command('git add .')
command('git commit -m Hello')
command('git push -u origin ' + cname)
command('git checkout master')
os.chdir(cdir)
if(course['confirmed']==""):
course['confirmed']=student['ion_user']
else:
course['confirmed']=course['confirmed']+ "," + student['ion_user']
#only 1 pereson on confirmeed
if(("," in course['unconfirmed']) == False):
course['unconfirmed']=""
#mutiple
else:
course['unconfirmed']= course['unconfirmed'].replace("," + student['ion_user'], "")
course['unconfirmed']= course['unconfirmed'].replace(student['ion_user']+",", "")
cinfo = {
"name": course['name'],
"repo": "",
"path": course['path'],
"teacher": course['name'],
"assignments": "",
"teacher": self.username,
"assignments": course['assignments'],
"default_file": "",
"confirmed": course["confirmed"],
"unconfirmed": course['unconfirmed']
}
print(putDB(cinfo, course['url']))
return True
#goes through list of studennts, tries to add, then request, return unconfirmed students
def reqAddStudentList(self, array, cname):
unconf = []
for i in range(len(array)):
a = array[i]
if(self.addStudent(a, cname) == False):
self.reqStudent(a, cname)
unconf.append(a)
return unconf
#add local path to student directory, make new instance in api
def addAssignment(self, path, course, due):
parts = path.split("/")
aname = parts[len(parts)-1]
if(os.path.isdir(path) == 0 or len(parts) < 3) or aname in self.sclass:
print("Not valid path.")
return
return False
if((parts[1] in self.sclass) == False):
print("Not in valid class directory")
return
return False
#parts of assignment name (Essay1, APLit)
if((course in aname) == False):
print("Assignment named incorrectly; could be "+ aname + "_" + course)
return False
ar = [x[2] for x in os.walk(path)]
print(ar)
for folder in ar:
if len(folder) == 0:
print("Assignment is completely empty, need a file.")
return
aname = parts[len(parts)-1]
print("Assignment is completely empty, needs a file.")
return False
p1 = course.split("_")[0]
if(p1 in aname == False):
print(aname + "incorrectly formated: must be " + aname + "_" + p1 + ".")
return
return False
try:
datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
except:
print("Due-date format is incorrect")
return
return False
ass = {
'name': aname,
'path':path,
'classes':course,
'teacher':self.username,
'due_date':due
}
postDB(ass, 'http://127.0.0.1:8000/api/assignments/' + aname + "/")
course = getDB("http://127.0.0.1:8000/api/classes/" + course)
if(aname in course['assignments']):
print("Assignment name already taken.")
return False
print(course['assignments'])
input()
#################### FINISH VERIFYING
if(os.path.exists(os.getcwd() + "/" + self.username + "/Students/" + course['name']) == False):
print("No students in this class yet")
return True
slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name'])
cdir = os.getcwd()
for st in slist:
@ -441,6 +474,38 @@ class Teacher:
os.chdir(cdir)
else:
print(st + " already has assignment")
#check if assignment already exists
r = requests.get(url = 'http://127.0.0.1:8000/api/assignments/' + aname, auth=('raffukhondaker','hackgroup1'))
if(r.status_code != 200):
ass = {
'name': aname,
'path':path,
'classes':course['name'],
'teacher':self.username,
'due_date':due
}
postDB(ass, 'http://127.0.0.1:8000/api/assignments/')
if(course['assignments'] == ""):
course['assignments'] = aname
else:
course['assignments'] = course['assignments'] + "," + aname
cinfo = {
"name": course['name'],
"repo": "",
"path": course['path'],
"teacher": "eharris1",
"assignments": course['assignments'],
"default_file": "",
"confirmed": course["confirmed"],
"unconfirmed": course['unconfirmed']
}
putDB(cinfo, "http://127.0.0.1:8000/api/classes/" + course['name'] + "/")
return True
else:
print("Assignment already addedd")
return True
#try to avoid
#copy modified assignments to student directories
@ -491,7 +556,7 @@ class Teacher:
command('git pull origin ' + course)
os.chdir(cdir)
def getHistory(self, student, course):
def getCommits(self, student, course, commits):
course = getDB("http://127.0.0.1:8000/api/classes/" + course)
try:
if((student in course['confirmed']) == False):
@ -503,10 +568,11 @@ class Teacher:
cdir = os.getcwd()
os.chdir(self.username + "/Students/" + course['name'] + "/" + student)
process = subprocess.Popen(['git', 'log', '-30', course['name']], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process = subprocess.Popen(['git', 'log', '-' + str(commits), course['name']], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
p=process.poll()
output = process.communicate()[0].decode('utf-8').split('\n\n')
months = ['Jan', 'Feb', 'Mar', "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"]
fout = []
for i in range(len(output)):
if("Date" in output[i]):
c = output[i].split("\n")
@ -524,9 +590,27 @@ class Teacher:
mon = m
d1 = datetime(int(date[4]), mon, int(date[2]), int(times[0]), int(times[1]))
#datetime1 = datetime.strptime('07/11/2019 02:45PM', '%m/%d/%Y %I:%M%p')
output[i] = [c[0], d1]
fout.append([c[0],d1])
#output[i] = [c[0], d1]
#print(output[i])
print(fout)
os.chdir(cdir)
return fout
def getChanges(self, student, course, commits):
course = getDB("http://127.0.0.1:8000/api/classes/" + course + "/")
ar = self.getCommits(student, course['name'], commits)
commit = ar[len(ar)-1][0]
start = ""
print("END:" + commit)
print("START: " + start)
cdir = os.getcwd()
os.chdir(self.username + "/Students/" + course['name'] + "/" + student)
process = subprocess.Popen(['git', 'diff', commit, '--name-status'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
p=process.poll()
output = process.communicate()[0].decode('utf-8')
print(output)
os.chdir(cdir)
return output
'''
assignment = {
@ -536,15 +620,14 @@ class Teacher:
'''
#check if assignment changed after due date
def afterSubmit(self, course, assignment, student):
'''
assignment = getDB()
'''
assignment = {
'name': assignment,
'due_date': "2020-04-11 16:58:33.383124",
'classes':course
}
log = self.getHistory(student, course)
assignment = getDB("http://127.0.0.1:8000/api/assignments/" + assignment)
# assignment = {
# 'name': assignment,
# 'due_date': "2020-04-11 16:58:33.383124",
# 'classes':course
# }
log = self.getCommits(student, course, 30)
assignment['due_date'] = datetime.strptime(assignment['due_date'], '%Y-%m-%d %H:%M:%S.%f')
late = False
cdir = os.getcwd()
@ -571,4 +654,24 @@ class Teacher:
data = getTeacher("eharris1")
t = Teacher(data)
t.getStudents("English11_eharris1")
# t.makeClass("APLit_eharris1")
#t.addAssignment("eharris1/APLit_eharris1/Lab3_APLit_eharris1", "APLit_eharris1", '2020-08-11 16:58:33.383124')
#ar = ['2022rkhondak','2022inafi','2023rumareti']
#extra = t.reqAddStudentList(ar, "APLit_eharris1")
#print(extra)
t.getStudents('2022rkhondak')
t.getChanges('2022rkhondak','APLit_eharris1', 10)
'''
TO-DO
- More checks
- add students to APLit_eharris1
- make new class, make newe assignment, add/req students, make assignment
- Add assignment to class after being made
- Check if assignment name is taken
- getUsage on student
- comit history
- check differences between commits
- check if student changes file after submissionn deadline
'''

View File

@ -1,2 +0,0 @@
import textract
text = textract.process('test.py')

View File

@ -0,0 +1,28 @@
# Generated by Django 3.0.7 on 2020-06-12 08:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0003_auto_20200612_0135'),
]
operations = [
migrations.AlterField(
model_name='classes',
name='assignments',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='classes',
name='default_file',
field=models.CharField(blank=True, default='', max_length=100),
),
migrations.AlterField(
model_name='classes',
name='repo',
field=models.URLField(blank=True, default=''),
),
]

View File

@ -20,11 +20,11 @@ class Assignment(models.Model):
class Classes(models.Model):
name = models.CharField(primary_key=True, max_length=100)
repo=models.URLField(default="")
repo=models.URLField(default="", blank=True)
path=models.CharField(max_length=100, default="")
teacher=models.CharField(max_length=100, default="")
assignments=models.CharField(max_length=100, default="")
default_file=models.CharField(max_length=100, default="")
assignments=models.TextField(default="", blank=True)
default_file=models.CharField(max_length=100, default="", blank=True)
confirmed=models.TextField(default="", blank=True)
unconfirmed=models.TextField(default="", blank=True)

BIN
chromedriver-mac Executable file

Binary file not shown.

View File

View File

@ -0,0 +1 @@

View File

@ -4,6 +4,7 @@ chardet==3.0.4
click==7.1.2
Django==3.0.7
django-cors-middleware==1.5.0
django-crispy-forms==1.9.1
django-oauth-toolkit==1.3.2
djangorestframework==3.11.0
idna==2.9