mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
Merge branch 'master' into development
This commit is contained in:
commit
3ab342119e
1
.sprofile
Normal file
1
.sprofile
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"username": "2022rkhondak", "grade": 10, "is_student": true, "password": "hackgroup1"}
|
1
.tprofile
Normal file
1
.tprofile
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"username": "eharris1", "is_student": false, "password": "hackgroup1"}
|
173
CLI/commands.py
173
CLI/commands.py
|
@ -1,173 +0,0 @@
|
||||||
from __future__ import print_function, unicode_literals
|
|
||||||
from PyInquirer import prompt, print_json
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
|
||||||
my_parser = argparse.ArgumentParser(prog='skool', description='Let SkoolOS control your system', epilog="Try again")
|
|
||||||
my_parser.add_argument('--init', action="store_true") #returns true if run argument
|
|
||||||
args = my_parser.parse_args()
|
|
||||||
|
|
||||||
update()
|
|
||||||
outputs = vars(args)
|
|
||||||
if(outputs['init']):
|
|
||||||
start()
|
|
||||||
'''
|
|
||||||
|
|
||||||
#already ccrerrated account through website, has to login
|
|
||||||
def update():
|
|
||||||
"""
|
|
||||||
Gets data from the database
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
return
|
|
||||||
|
|
||||||
def yesorno(question):
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'response',
|
|
||||||
'message': question,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
answers = prompt(questions)
|
|
||||||
if(answers["response"] == "y"):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def login():
|
|
||||||
"""
|
|
||||||
Login to the website with a username and password
|
|
||||||
:return: user information json if successful, None otherwise
|
|
||||||
"""
|
|
||||||
#enter username
|
|
||||||
#enter password
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'webmail',
|
|
||||||
'message': 'What\'s TJ Webmail',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'password',
|
|
||||||
'name': 'password',
|
|
||||||
'message': 'Password?',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
user = prompt(questions)
|
|
||||||
#reading from json of users (replace w GET to database) to check if user is registered
|
|
||||||
with open('users.json', 'r') as json_file:
|
|
||||||
data = json.load(json_file)
|
|
||||||
for i in range(len(data)):
|
|
||||||
if user["webmail"] == data[i]["webmail"]:
|
|
||||||
if(user["password"] == data[i]["password"]):
|
|
||||||
print("Logged in!")
|
|
||||||
return data[i]
|
|
||||||
else:
|
|
||||||
print("Password incorrect. Try again.")
|
|
||||||
return None
|
|
||||||
print("User not found. Please Try again")
|
|
||||||
return None
|
|
||||||
|
|
||||||
#did not create account through website, has to signup/login
|
|
||||||
def signup():
|
|
||||||
"""
|
|
||||||
Used to create an account for the service.
|
|
||||||
Called if the user does not have an existing account and must create one.
|
|
||||||
:return: the new user account
|
|
||||||
"""
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'first-name',
|
|
||||||
'message': 'What\'s your first name',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'last-name',
|
|
||||||
'message': 'What\'s your last name?',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'list',
|
|
||||||
'name': 'grade',
|
|
||||||
'message': 'Grade?',
|
|
||||||
'choices':["9","10","11","12"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'webmail',
|
|
||||||
'message': 'What\'s your TJ Webmail?',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'password',
|
|
||||||
'name': 'password',
|
|
||||||
'message': 'Password?',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
user = prompt(questions)
|
|
||||||
for i in user:
|
|
||||||
if user[i] == "":
|
|
||||||
print("Some forms were left blank. Try again.\n")
|
|
||||||
return None
|
|
||||||
if len(user["password"]) < 6:
|
|
||||||
print("Password is too short. Try again.")
|
|
||||||
return None
|
|
||||||
if (("@tjhsst.edu" in user['webmail']) == False):
|
|
||||||
print("Webmail entered was not a @tjhhsst.edu. Try again.")
|
|
||||||
return None
|
|
||||||
|
|
||||||
user["classes"] = []
|
|
||||||
with open('users.json', 'r') as json_file:
|
|
||||||
data = json.load(json_file)
|
|
||||||
data.append(user)
|
|
||||||
open("users.json", "w").write(str(json.dumps(data)))
|
|
||||||
return user
|
|
||||||
|
|
||||||
def relogin():
|
|
||||||
"""
|
|
||||||
Login to an already verified user account
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'list',
|
|
||||||
'name': 'choice',
|
|
||||||
'message': '',
|
|
||||||
'choices':["Continue as current user","Login into new user","Sign up into new account"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
answer = prompt(questions)
|
|
||||||
|
|
||||||
|
|
||||||
def setup(user):
|
|
||||||
#Read classes/assignenments and setup directory:
|
|
||||||
#SkoolOS/Math/Week1
|
|
||||||
"""
|
|
||||||
Reads classes and assignments of/for the user and properly sets of their work directory
|
|
||||||
:param user:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
for c in user["classes"]:
|
|
||||||
os.makedirs(c)
|
|
||||||
for a in user["classes"][c]:
|
|
||||||
os.makedirs(c + "/" + a)
|
|
||||||
|
|
||||||
def start():
|
|
||||||
"""
|
|
||||||
Prompts the user for whether or not they have an account and allows them to login/signup depending on their response
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
if(os.path.exists(".login.txt") == False):
|
|
||||||
b = yesorno("Do you have a SkoolOS account?(y/N)")
|
|
||||||
if(b):
|
|
||||||
user = login()
|
|
||||||
if(user != None):
|
|
||||||
setup(user)
|
|
||||||
open(".login.txt", "w").write(str(user))
|
|
||||||
else:
|
|
||||||
user = signup()
|
|
||||||
if(user != None):
|
|
||||||
open(".login.txt").write(str(user))
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Sign in with Ion</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
Sign in with
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,23 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Sign into Ion</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background: #5ac8fb;
|
|
||||||
background: -webkit-linear-gradient(to left, #52edc7, #5ac8fb);
|
|
||||||
background: linear-gradient(to left, #52edc7, #5ac8fb);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="d-flex align-items-center justify-content-center" style="height: 100vh">
|
|
||||||
<a href="AUTH_URL" 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>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,256 +0,0 @@
|
||||||
import subprocess
|
|
||||||
import os
|
|
||||||
import requests
|
|
||||||
import webbrowser
|
|
||||||
import pprint
|
|
||||||
import json
|
|
||||||
import shutil
|
|
||||||
import time
|
|
||||||
import pyperclip
|
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
|
||||||
|
|
||||||
#get teacher info from api
|
|
||||||
def getStudent(ion_user):
|
|
||||||
URL = "http://127.0.0.1:8000/students/" + ion_user + "/"
|
|
||||||
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
if(r.status_code == 200):
|
|
||||||
data = r.json()
|
|
||||||
return data
|
|
||||||
elif(r.status_code == 404):
|
|
||||||
return None
|
|
||||||
print("Make new account!")
|
|
||||||
elif(r.status_code == 403):
|
|
||||||
return None
|
|
||||||
print("Invalid username/password")
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
print(r.status_code)
|
|
||||||
|
|
||||||
def getDB(url):
|
|
||||||
r = requests.get(url = url, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("GET:" + str(r.status_code))
|
|
||||||
return(r.json())
|
|
||||||
|
|
||||||
def postDB(data, url):
|
|
||||||
r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("POST:" + str(r.status_code))
|
|
||||||
return(r.json())
|
|
||||||
|
|
||||||
def putDB(data, url):
|
|
||||||
r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("PUT:" + str(r.status_code))
|
|
||||||
return(r.json())
|
|
||||||
|
|
||||||
def delDB(url):
|
|
||||||
r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("DELETE:" + str(r.status_code))
|
|
||||||
return None
|
|
||||||
|
|
||||||
def command(command):
|
|
||||||
ar = []
|
|
||||||
command = command.split(" ")
|
|
||||||
for c in command:
|
|
||||||
ar.append(c)
|
|
||||||
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
p=process.poll()
|
|
||||||
output = process.communicate()[1]
|
|
||||||
print(output.decode('utf-8'))
|
|
||||||
|
|
||||||
####################################################################################################################################
|
|
||||||
|
|
||||||
#public methods: deleteClass, makeClass, update
|
|
||||||
class Student:
|
|
||||||
def __init__(self, data):
|
|
||||||
# teacher info already stored in API
|
|
||||||
# intitialze fields after GET request
|
|
||||||
self.first_name=data['first_name']
|
|
||||||
self.last_name=data['last_name']
|
|
||||||
self.git=data['git']
|
|
||||||
self.username=data['ion_user']
|
|
||||||
self.url= "http://127.0.0.1:8000/students/" + self.username + "/"
|
|
||||||
self.email = data['email']
|
|
||||||
self.grade = data['grade']
|
|
||||||
self.student_id=data['student_id']
|
|
||||||
self.completed = data['completed']
|
|
||||||
#classes in id form (Example: 4,5)
|
|
||||||
|
|
||||||
#storing actual classes
|
|
||||||
cid=data['classes'].split(",")
|
|
||||||
try:
|
|
||||||
cid.remove('')
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
cid.remove("")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
classes=[]
|
|
||||||
for c in cid:
|
|
||||||
url = "http://127.0.0.1:8000/classes/" + str(c) + "/"
|
|
||||||
classes.append(getDB(url))
|
|
||||||
|
|
||||||
self.classes = classes
|
|
||||||
self.sclass=str(data['classes'])
|
|
||||||
|
|
||||||
#storing added_to classes
|
|
||||||
nid=data['added_to'].split(",")
|
|
||||||
try:
|
|
||||||
nid.remove('')
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
nid.remove("")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
nclasses=[]
|
|
||||||
for c in nid:
|
|
||||||
url = "http://127.0.0.1:8000/classes/" + str(c) + "/"
|
|
||||||
nclasses.append(getDB(url))
|
|
||||||
|
|
||||||
self.new = nclasses
|
|
||||||
self.snew=str(data['added_to'])
|
|
||||||
if(os.path.isdir(self.username)):
|
|
||||||
print("Synced to " + self.username)
|
|
||||||
else:
|
|
||||||
os.mkdir(self.username)
|
|
||||||
|
|
||||||
|
|
||||||
#update API and Github, all assignments / classes
|
|
||||||
def update(self):
|
|
||||||
#lists all classes
|
|
||||||
ignore=['.DS_Store']
|
|
||||||
classes = os.listdir(self.username)
|
|
||||||
for i in ignore:
|
|
||||||
try:
|
|
||||||
classes.remove(i)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
for i in range(len(classes)):
|
|
||||||
c = classes[i]
|
|
||||||
path = self.username + "/" + c
|
|
||||||
#lists all assignments and default files
|
|
||||||
#push to git
|
|
||||||
isclass = False
|
|
||||||
for d in os.listdir(path):
|
|
||||||
if(d == '.git'):
|
|
||||||
isclass=True
|
|
||||||
break
|
|
||||||
if(isclass):
|
|
||||||
loc = os.getcwd()
|
|
||||||
os.chdir(path)
|
|
||||||
command('git fetch origin')
|
|
||||||
command('git checkout ' + self.username)
|
|
||||||
command('git add .')
|
|
||||||
command('git commit -m ' + self.username + '-update')
|
|
||||||
command('git push -u origin ' + self.username)
|
|
||||||
command('git merge master')
|
|
||||||
os.chdir(loc)
|
|
||||||
print("Updated: " + c)
|
|
||||||
else:
|
|
||||||
print(d + " is not a class")
|
|
||||||
|
|
||||||
#class name format: <course-name>_<ion_user>
|
|
||||||
|
|
||||||
|
|
||||||
#add classes from 'new' field
|
|
||||||
def addClass(self, cid):
|
|
||||||
if((cid in self.snew) == False):
|
|
||||||
if((cid in self.sclass) == True):
|
|
||||||
print("Already enrolled in this class.")
|
|
||||||
else:
|
|
||||||
print("Not added by teacher yet.")
|
|
||||||
return None
|
|
||||||
data = getDB('http://127.0.0.1:8000/classes/'+cid)
|
|
||||||
|
|
||||||
#clone class repo and make student branch (branch name: username)
|
|
||||||
os.chdir(self.username)
|
|
||||||
command("git clone " + data['repo'])
|
|
||||||
os.chdir(data['name'])
|
|
||||||
command("git checkout " + self.username)
|
|
||||||
command("git push -u origin " + self.username)
|
|
||||||
|
|
||||||
self.classes.append(data)
|
|
||||||
if(len(self.sclass)==0):
|
|
||||||
self.sclass = data['id']
|
|
||||||
else:
|
|
||||||
self.sclass = self.sclass + "," + str(data['id'])
|
|
||||||
|
|
||||||
#upddate self.new
|
|
||||||
s=""
|
|
||||||
nar = ''
|
|
||||||
for i in range(len(self.new)):
|
|
||||||
if(self.new[i]['id'] == int(data['id'])):
|
|
||||||
print("DELETE: " + self.new[i]['name'])
|
|
||||||
del self.new[i]
|
|
||||||
#recreate sclass field, using ids
|
|
||||||
for c in self.new:
|
|
||||||
s = s + str(c['id']) + ","
|
|
||||||
nar.append(c)
|
|
||||||
self.snew=s
|
|
||||||
self.new=nar
|
|
||||||
break
|
|
||||||
|
|
||||||
#update teacher instance in db, classes field
|
|
||||||
data={
|
|
||||||
'first_name':self.first_name,
|
|
||||||
'last_name':self.last_name,
|
|
||||||
'git':self.git,
|
|
||||||
'ion_user':self.username,
|
|
||||||
'student_id':self.student_id,
|
|
||||||
'added_to':self.snew,
|
|
||||||
'url':self.url,
|
|
||||||
'classes':self.sclass,
|
|
||||||
'email':self.email,
|
|
||||||
'grade':self.grade,
|
|
||||||
'completed':self.completed
|
|
||||||
}
|
|
||||||
print(self.url)
|
|
||||||
print(putDB(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={
|
|
||||||
'first_name':self.first_name,
|
|
||||||
'last_name':self.last_name,
|
|
||||||
'git':self.git,
|
|
||||||
'ion_user':self.username,
|
|
||||||
'student_id':self.student_id,
|
|
||||||
'added_to':self.snew,
|
|
||||||
'url':self.url,
|
|
||||||
'classes':self.sclass,
|
|
||||||
'email':self.email,
|
|
||||||
'grade':self.grade,
|
|
||||||
'completed':self.completed
|
|
||||||
}
|
|
||||||
#print(putDB(data, "http://127.0.0.1:8000/students/" + self.username + "/"))
|
|
||||||
|
|
||||||
data = getStudent("2022rkhondak")
|
|
||||||
s = Student(data)
|
|
||||||
s.update()
|
|
|
@ -1,23 +0,0 @@
|
||||||
from http.server import HTTPServer
|
|
||||||
|
|
||||||
class HTTPServer(BaseHTTPServer.HTTPServer):
|
|
||||||
|
|
||||||
_continue = True
|
|
||||||
|
|
||||||
def serve_until_shutdown(self):
|
|
||||||
while self._continue:
|
|
||||||
self.handle_request()
|
|
||||||
|
|
||||||
def shutdown(self):
|
|
||||||
self._continue = False
|
|
||||||
# We fire a last request at the server in order to take it out of the
|
|
||||||
# while loop in `self.serve_until_shutdown`.
|
|
||||||
try:
|
|
||||||
urllib2.urlopen(
|
|
||||||
'http://%s:%s/' % (self.server_name, self.server_port))
|
|
||||||
except urllib2.URLError:
|
|
||||||
# If the server is already shut down, we receive a socket error,
|
|
||||||
# which we ignore.
|
|
||||||
pass
|
|
||||||
self.server_close()
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ class Student:
|
||||||
classes = self.classes
|
classes = self.classes
|
||||||
for c in classes:
|
for c in classes:
|
||||||
print(c['name'])
|
print(c['name'])
|
||||||
alist = c['assignments'].split(",")
|
alist = c['assignments']
|
||||||
for a in alist:
|
for a in alist:
|
||||||
ass = getDB("http://127.0.0.1:8000/api/assignments/" + a)
|
ass = getDB("http://127.0.0.1:8000/api/assignments/" + a)
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
@ -331,12 +331,13 @@ class Student:
|
||||||
if c['name'] == courses:
|
if c['name'] == courses:
|
||||||
command("git checkout " + courses)
|
command("git checkout " + courses)
|
||||||
print(os.listdir())
|
print(os.listdir())
|
||||||
return
|
break
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
print("Class not found")
|
print("Class not found")
|
||||||
return
|
return
|
||||||
|
|
||||||
def exitCLI(self):
|
def exitCLI(self):
|
||||||
|
print(os.getcwd())
|
||||||
self.update()
|
self.update()
|
||||||
command("git checkout master")
|
command("git checkout master")
|
||||||
|
|
||||||
|
@ -368,11 +369,11 @@ class Student:
|
||||||
command('git checkout master')
|
command('git checkout master')
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
|
|
||||||
data = getStudent("2022rkhondak")
|
# data = getStudent("2022rkhondak")
|
||||||
s = Student(data)
|
# s = Student(data)
|
||||||
#s.viewClass("APLit_eharris1")
|
# s.viewClass("APLit_eharris1")
|
||||||
s.addClass("APLit_eharris1")
|
# #s.addClass("APLit_eharris1")
|
||||||
# #s.update()
|
# # #s.update()
|
||||||
# s.exitCLI()
|
# s.exitCLI()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
372
CLI/t-git-old.py
372
CLI/t-git-old.py
|
@ -1,372 +0,0 @@
|
||||||
import subprocess
|
|
||||||
import os
|
|
||||||
import requests
|
|
||||||
import webbrowser
|
|
||||||
import pprint
|
|
||||||
import json
|
|
||||||
import shutil
|
|
||||||
import time
|
|
||||||
import pyperclip
|
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
|
||||||
|
|
||||||
#get teacher info from api
|
|
||||||
def getTeacher(ion_user):
|
|
||||||
URL = "http://127.0.0.1:8000/teachers/" + ion_user + "/"
|
|
||||||
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
if(r.status_code == 200):
|
|
||||||
data = r.json()
|
|
||||||
return data
|
|
||||||
elif(r.status_code == 404):
|
|
||||||
return None
|
|
||||||
print("Make new account!")
|
|
||||||
elif(r.status_code == 403):
|
|
||||||
return None
|
|
||||||
print("Invalid username/password")
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
print(r.status_code)
|
|
||||||
|
|
||||||
def getDB(url):
|
|
||||||
r = requests.get(url = url, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("GET:" + str(r.status_code))
|
|
||||||
return(r.json())
|
|
||||||
|
|
||||||
def postDB(data, url):
|
|
||||||
r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("POST:" + str(r.status_code))
|
|
||||||
return(r.json())
|
|
||||||
|
|
||||||
def putDB(data, url):
|
|
||||||
r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("PUT:" + str(r.status_code))
|
|
||||||
return(r.json())
|
|
||||||
|
|
||||||
def delDB(url):
|
|
||||||
r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("DELETE:" + str(r.status_code))
|
|
||||||
return None
|
|
||||||
|
|
||||||
def command(command):
|
|
||||||
ar = []
|
|
||||||
command = command.split(" ")
|
|
||||||
for c in command:
|
|
||||||
ar.append(c)
|
|
||||||
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
p=process.poll()
|
|
||||||
output = process.communicate()[1]
|
|
||||||
#print(output.decode('utf-8'))
|
|
||||||
|
|
||||||
####################################################################################################################################
|
|
||||||
|
|
||||||
#public methods: deleteClass, makeClass, update
|
|
||||||
class Teacher:
|
|
||||||
def __init__(self, data):
|
|
||||||
# teacher info already stored in API
|
|
||||||
# intitialze fields after GET request
|
|
||||||
self.first_name=data['first_name']
|
|
||||||
self.last_name=data['last_name']
|
|
||||||
self.git=data['git']
|
|
||||||
self.username=data['ion_user']
|
|
||||||
self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/"
|
|
||||||
self.email = data['email']
|
|
||||||
#classes in id form (Example: 4,5)
|
|
||||||
|
|
||||||
cid=data['classes'].split(",")
|
|
||||||
try:
|
|
||||||
cid.remove('')
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
cid.remove("")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
classes=[]
|
|
||||||
for c in cid:
|
|
||||||
url = "http://127.0.0.1:8000/classes/" + str(c) + "/"
|
|
||||||
classes.append(getDB(url))
|
|
||||||
|
|
||||||
self.classes = classes
|
|
||||||
self.sclass=str(data['classes'])
|
|
||||||
if(os.path.isdir(self.username)):
|
|
||||||
print("Synced to " + self.username)
|
|
||||||
else:
|
|
||||||
os.mkdir(self.username)
|
|
||||||
|
|
||||||
|
|
||||||
#update API and Github, all assignments / classes
|
|
||||||
def update(self):
|
|
||||||
#lists all classes
|
|
||||||
ignore=['.git','.DS_Store']
|
|
||||||
classes = os.listdir(self.username)
|
|
||||||
for i in ignore:
|
|
||||||
try:
|
|
||||||
classes.remove(i)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
#list of classes that have been deleted (not with deleteClass)
|
|
||||||
extra = []
|
|
||||||
for c in self.classes:
|
|
||||||
extra.append(c)
|
|
||||||
for i in range(len(extra)):
|
|
||||||
e = extra[i]['path']
|
|
||||||
extra[i] = e
|
|
||||||
print("Extra: "+str(extra))
|
|
||||||
print("Local:" + str(classes))
|
|
||||||
#checks all class directories first
|
|
||||||
for c in classes:
|
|
||||||
path = self.username + "/" + c
|
|
||||||
if(self.checkClass(path) == False):
|
|
||||||
return
|
|
||||||
extra.remove(path)
|
|
||||||
print("Current classes: " + path)
|
|
||||||
|
|
||||||
for e in extra:
|
|
||||||
self.deleteClass(e)
|
|
||||||
|
|
||||||
for i in range(len(classes)):
|
|
||||||
c = classes[i]
|
|
||||||
path = self.username + "/" + c
|
|
||||||
#lists all assignments and default files
|
|
||||||
#if no .git, directory not synced to git or API
|
|
||||||
if (self.checkInDB(path)==False):
|
|
||||||
self.addClass(path)
|
|
||||||
else:
|
|
||||||
#push to git
|
|
||||||
loc = os.getcwd()
|
|
||||||
os.chdir(path)
|
|
||||||
command('git fetch origin')
|
|
||||||
command('git pull origin master')
|
|
||||||
command('git add .')
|
|
||||||
command('git commit -m "Update"')
|
|
||||||
command('git push -u origin master')
|
|
||||||
os.chdir(loc)
|
|
||||||
|
|
||||||
#class name format: <course-name>_<ion_user>
|
|
||||||
|
|
||||||
#turn existing directory into class, Pre-condition: directory exists
|
|
||||||
#relative path to class: 2022rkhondak/Math4
|
|
||||||
def checkClass(self,path):
|
|
||||||
cname = path.split("/")
|
|
||||||
cname = cname[len(cname)-1]
|
|
||||||
if(os.path.isfile(path)):
|
|
||||||
print(path + " must be in a Class directory.")
|
|
||||||
return False
|
|
||||||
if(("_" + self.username) in cname) == False:
|
|
||||||
print("Incorrect class name: Must be in the format: " + self.username+ "/<course-name>_<ion_user>, not " + path)
|
|
||||||
return False
|
|
||||||
dirs = os.listdir(path)
|
|
||||||
#checks if there is a file (not within Assignments) in class, need at least 1
|
|
||||||
deffile = False
|
|
||||||
#checks if there is a file in an Assignment, need at least 1 (default True in case no assignments)
|
|
||||||
as_file = True
|
|
||||||
as_bad = ""
|
|
||||||
|
|
||||||
for d in dirs:
|
|
||||||
if(os.path.isfile(d)):
|
|
||||||
deffile=True
|
|
||||||
else:
|
|
||||||
#checks if there is a file in an Assignment, need at least 1
|
|
||||||
as_file = False
|
|
||||||
asdir = os.listdir(path + "/" + d)
|
|
||||||
for a in asdir:
|
|
||||||
if(os.path.isfile(path + "/" + d + "/" +a)):
|
|
||||||
as_file=True
|
|
||||||
if(as_file==False):
|
|
||||||
as_bad = d
|
|
||||||
break
|
|
||||||
if(as_file==False):
|
|
||||||
print("Assignment '" + as_bad + "' does not have a default file!")
|
|
||||||
return False
|
|
||||||
|
|
||||||
if(deffile==False):
|
|
||||||
print("Need a default file in the " + path + " Directory!")
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def checkInDB(self, path):
|
|
||||||
n = path.split("/")
|
|
||||||
n = n[len(n)-1]
|
|
||||||
for c in self.classes:
|
|
||||||
if(n == c['name']):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
#adds class to git, not API
|
|
||||||
#Assuming valid class name
|
|
||||||
def addClasstoGit(self, path):
|
|
||||||
cname = path.split("/")
|
|
||||||
cname = cname[len(cname)-1]
|
|
||||||
#push to remote repo
|
|
||||||
url='https://github.com/' + self.git + "/" + cname
|
|
||||||
if(requests.get(url).status_code != 200):
|
|
||||||
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
|
||||||
try:
|
|
||||||
pyperclip.copy(cname)
|
|
||||||
print(cname + " copied to clipboard.")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
time.sleep(2)
|
|
||||||
webbrowser.open('https://github.com/new')
|
|
||||||
input("Repo created? (Press any key to continue)\n")
|
|
||||||
|
|
||||||
print(url)
|
|
||||||
while(requests.get(url).status_code != 200):
|
|
||||||
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
|
||||||
if(r=="N" or r=="No"):
|
|
||||||
return None
|
|
||||||
cdir = os.getcwd()
|
|
||||||
os.chdir(path)
|
|
||||||
command('git init')
|
|
||||||
command('git add .')
|
|
||||||
command('git commit -m Hello_Class')
|
|
||||||
command('git remote add origin ' + url + '.git')
|
|
||||||
command('git push -u origin master')
|
|
||||||
else:
|
|
||||||
cdir = os.getcwd()
|
|
||||||
os.chdir(path)
|
|
||||||
print("Repo already exists. Cloning instead.")
|
|
||||||
command('git clone')
|
|
||||||
command('git fetch origin')
|
|
||||||
command('git pull')
|
|
||||||
command('git add .')
|
|
||||||
command('git commit -m Hello_Class')
|
|
||||||
command('git push -u origin master')
|
|
||||||
os.chdir(cdir)
|
|
||||||
print(cdir)
|
|
||||||
data={
|
|
||||||
'name':cname,
|
|
||||||
'repo':url,
|
|
||||||
'path':path,
|
|
||||||
'teacher':self.username,
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
|
|
||||||
#make class from existing directory, add to git and api
|
|
||||||
def addClass(self, path):
|
|
||||||
if (self.checkClass(path)):
|
|
||||||
data = self.addClasstoGit(path)
|
|
||||||
#make class instance in db
|
|
||||||
data = postDB(data, 'http://127.0.0.1:8000/classes/')
|
|
||||||
#add to instance
|
|
||||||
#upate self.classes
|
|
||||||
self.classes.append(data)
|
|
||||||
if(len(self.sclass)==0):
|
|
||||||
self.sclass = data['id']
|
|
||||||
else:
|
|
||||||
self.sclass = self.sclass + "," + str(data['id'])
|
|
||||||
|
|
||||||
#update teacher instance in db, classes field
|
|
||||||
data={
|
|
||||||
'first_name':self.first_name,
|
|
||||||
'last_name':self.last_name,
|
|
||||||
'git':self.git,
|
|
||||||
'ion_user':self.username,
|
|
||||||
'url':self.url,
|
|
||||||
'classes':self.sclass,
|
|
||||||
'email':self.email
|
|
||||||
}
|
|
||||||
putDB(data, self.url)
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
#make a new class from scratch
|
|
||||||
#subject: string, assignments: list
|
|
||||||
#class name must be: <subject>_<ion_user>
|
|
||||||
def makeClass(self, cname, assignments):
|
|
||||||
#check if class exists
|
|
||||||
path = self.username + "/" + cname
|
|
||||||
if(os.path.exists(path)):
|
|
||||||
print("Class already exists: " + cname)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
if((("_" + self.username) in cname) == False):
|
|
||||||
print("class name must be: "+ cname + "_" + self.username)
|
|
||||||
return
|
|
||||||
cdir = os.getcwd()
|
|
||||||
os.mkdir(path)
|
|
||||||
f=open(path + "/README.md", "w")
|
|
||||||
f.close()
|
|
||||||
#push to remote repo
|
|
||||||
os.chdir(path)
|
|
||||||
for a in assignments:
|
|
||||||
os.mkdir(a)
|
|
||||||
f=open(a + "/instructions.txt", "w")
|
|
||||||
f.close()
|
|
||||||
os.chdir(cdir)
|
|
||||||
|
|
||||||
data = self.addClass(path)
|
|
||||||
return data
|
|
||||||
|
|
||||||
def deleteClass(self, path):
|
|
||||||
if(os.path.exists(path) == False):
|
|
||||||
print(path + " does not exist locally.")
|
|
||||||
resp = input("Do you want to delete " + path + " from the SkoolOS system? (y/N) ")
|
|
||||||
if(resp != 'y'):
|
|
||||||
return
|
|
||||||
|
|
||||||
cname = path.split("/")
|
|
||||||
cname = cname[len(cname)-1]
|
|
||||||
cid = None
|
|
||||||
repo = ''
|
|
||||||
for c in self.classes:
|
|
||||||
if cname == c['name']:
|
|
||||||
cid = str(c['id'])
|
|
||||||
repo = c['repo']
|
|
||||||
|
|
||||||
#remove from api
|
|
||||||
for i in range(len(self.classes)):
|
|
||||||
if(self.classes[i]['id'] == int(cid)):
|
|
||||||
print("DELETE: " + self.classes[i]['name'])
|
|
||||||
del self.classes[i]
|
|
||||||
s=""
|
|
||||||
#recreate sclass field, using ids
|
|
||||||
for c in self.classes:
|
|
||||||
s = s + str(c['id']) + ","
|
|
||||||
print(s)
|
|
||||||
s = s[:-1]
|
|
||||||
print(s)
|
|
||||||
data={
|
|
||||||
'first_name':self.first_name,
|
|
||||||
'last_name':self.last_name,
|
|
||||||
'git':self.git,
|
|
||||||
'ion_user':self.username,
|
|
||||||
'url':self.url,
|
|
||||||
'classes':s,
|
|
||||||
'email':self.email
|
|
||||||
}
|
|
||||||
print(putDB(data, self.url))
|
|
||||||
delDB("http://127.0.0.1:8000/classes/" + cid + "/")
|
|
||||||
break
|
|
||||||
|
|
||||||
#remove locally
|
|
||||||
try:
|
|
||||||
shutil.rmtree(path)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
#remove from git
|
|
||||||
input("Delete repository: " + cname + ". Scroll to the bottom of the page and press 'Delete this repository' (Press any key to continue) ")
|
|
||||||
print(repo)
|
|
||||||
time.sleep(2)
|
|
||||||
webbrowser.open(repo + "/settings")
|
|
||||||
input("Repo deleted? (Press any key to continue) ")
|
|
||||||
|
|
||||||
print(repo)
|
|
||||||
while(requests.get(repo).status_code == 200):
|
|
||||||
r = input("Repo still no deleted yet. (Press any key to continue after repo deleted, or 'N' to exit)\n")
|
|
||||||
if(r=="N" or r=="No" or r=='n'):
|
|
||||||
return None
|
|
||||||
|
|
||||||
#make student repo by student id
|
|
||||||
def addStudent(self,stid):
|
|
||||||
print(stid)
|
|
||||||
|
|
||||||
def comment(self):
|
|
||||||
print("heheheh")
|
|
||||||
|
|
||||||
data = getTeacher("eharris1")
|
|
||||||
t = Teacher(data)
|
|
||||||
t.makeClass('English11_eharris1', ["Essay1"])
|
|
||||||
t.update()
|
|
|
@ -365,6 +365,7 @@ class Teacher:
|
||||||
def addAssignment(self, path, course, due):
|
def addAssignment(self, path, course, due):
|
||||||
parts = path.split("/")
|
parts = path.split("/")
|
||||||
aname = parts[len(parts)-1]
|
aname = parts[len(parts)-1]
|
||||||
|
oname = aname + "_" + course
|
||||||
|
|
||||||
if(os.path.isdir(path) == 0 or len(parts) < 3) or aname in str(self.classes):
|
if(os.path.isdir(path) == 0 or len(parts) < 3) or aname in str(self.classes):
|
||||||
print("Not valid path.")
|
print("Not valid path.")
|
||||||
|
@ -373,9 +374,9 @@ class Teacher:
|
||||||
print("Not in valid class directory")
|
print("Not in valid class directory")
|
||||||
return False
|
return False
|
||||||
#parts of assignment name (Essay1, APLit)
|
#parts of assignment name (Essay1, APLit)
|
||||||
if((course in aname) == False):
|
# if((course in aname) == False):
|
||||||
print("Assignment named incorrectly; could be "+ aname + "_" + course)
|
# print("Assignment named incorrectly; could be "+ aname + "_" + course)
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
ar = [x[2] for x in os.walk(path)]
|
ar = [x[2] for x in os.walk(path)]
|
||||||
print(ar)
|
print(ar)
|
||||||
|
@ -383,10 +384,10 @@ class Teacher:
|
||||||
if len(folder) == 0:
|
if len(folder) == 0:
|
||||||
print("Assignment is completely empty, needs a file.")
|
print("Assignment is completely empty, needs a file.")
|
||||||
return False
|
return False
|
||||||
p1 = course.split("_")[0]
|
# p1 = course.split("_")[0]
|
||||||
if(p1 in aname == False):
|
# if(p1 in aname == False):
|
||||||
print(aname + "incorrectly formated: must be " + aname + "_" + p1 + ".")
|
# print(aname + "incorrectly formated: must be " + aname + "_" + p1 + ".")
|
||||||
return False
|
# return False
|
||||||
try:
|
try:
|
||||||
datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
||||||
except:
|
except:
|
||||||
|
@ -397,9 +398,8 @@ class Teacher:
|
||||||
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
|
||||||
|
|
||||||
print(course['assignments'])
|
print(course['assignments'])
|
||||||
input()
|
print(aname)
|
||||||
#################### FINISH VERIFYING
|
#################### FINISH VERIFYING
|
||||||
|
|
||||||
if(os.path.exists(os.getcwd() + "/" + self.username + "/Students/" + course['name']) == False):
|
if(os.path.exists(os.getcwd() + "/" + self.username + "/Students/" + course['name']) == False):
|
||||||
|
@ -428,14 +428,14 @@ class Teacher:
|
||||||
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=('raffukhondaker','hackgroup1'))
|
||||||
if(r.status_code != 200):
|
if(r.status_code != 200):
|
||||||
ass = {
|
ass = {
|
||||||
'name': aname,
|
'name': oname,
|
||||||
'path':path,
|
'path':path,
|
||||||
'classes':course['name'],
|
'classes':course['name'],
|
||||||
'teacher':self.username,
|
'teacher':self.username,
|
||||||
'due_date':due
|
'due_date':due
|
||||||
}
|
}
|
||||||
postDB(ass, 'http://127.0.0.1:8000/api/assignments/')
|
postDB(ass, 'http://127.0.0.1:8000/api/assignments/')
|
||||||
course['assignments'].append(aname)
|
course['assignments'].append(oname)
|
||||||
|
|
||||||
cinfo = {
|
cinfo = {
|
||||||
"assignments": course['assignments'],
|
"assignments": course['assignments'],
|
||||||
|
@ -451,6 +451,7 @@ class Teacher:
|
||||||
def updateAssignment(self, path, course, due):
|
def updateAssignment(self, path, course, due):
|
||||||
parts = path.split("/")
|
parts = path.split("/")
|
||||||
aname = parts[len(parts)-1]
|
aname = parts[len(parts)-1]
|
||||||
|
oname=aname + "_" + course
|
||||||
if(os.path.isdir(path) == False):
|
if(os.path.isdir(path) == False):
|
||||||
print(path + " is not an assignment.")
|
print(path + " is not an assignment.")
|
||||||
return
|
return
|
||||||
|
@ -460,7 +461,7 @@ class Teacher:
|
||||||
d = {
|
d = {
|
||||||
'due_date':due,
|
'due_date':due,
|
||||||
}
|
}
|
||||||
patchDB(d, 'http://localhost:8000/api/assignments/' + aname + "/")
|
print(patchDB(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")
|
||||||
|
@ -471,19 +472,15 @@ class Teacher:
|
||||||
for st in slist:
|
for st in slist:
|
||||||
if st in course['confirmed']:
|
if st in course['confirmed']:
|
||||||
spath = os.path.join(os.getcwd() + "/" + self.username + "/Students/" + course['name'], st)
|
spath = os.path.join(os.getcwd() + "/" + self.username + "/Students/" + course['name'], st)
|
||||||
if(os.path.exists(spath + "/" + aname) == False):
|
print(st)
|
||||||
os.mkdir(spath + "/" + aname)
|
print(copy_tree(path, spath + "/" + aname))
|
||||||
print(st)
|
os.chdir(spath)
|
||||||
print(copy_tree(path, spath + "/" + aname))
|
#command('git checkout ' + course['name'])
|
||||||
os.chdir(spath)
|
command('git add .')
|
||||||
command('git checkout ' + course['name'])
|
command('git commit -m Hello')
|
||||||
command('git pull origin ' + course['name'])
|
command('git pull origin ' + course['name'])
|
||||||
command('git add .')
|
command('git push -u origin ' + course['name'])
|
||||||
command('git commit -m Hello')
|
os.chdir(cdir)
|
||||||
command('git push -u origin ' + course['name'])
|
|
||||||
os.chdir(cdir)
|
|
||||||
else:
|
|
||||||
print(st + " already has assignment")
|
|
||||||
|
|
||||||
#pull student's work, no modifications
|
#pull student's work, no modifications
|
||||||
def getStudents(self, course):
|
def getStudents(self, course):
|
||||||
|
@ -595,10 +592,10 @@ class Teacher:
|
||||||
print("heheheh")
|
print("heheheh")
|
||||||
|
|
||||||
|
|
||||||
data = getTeacher("eharris1")
|
# data = getTeacher("eharris1")
|
||||||
t = Teacher(data)
|
# t = Teacher(data)
|
||||||
#t.makeClass("APLit_eharris1")
|
#t.makeClass("APLit_eharris1")
|
||||||
#t.addAssignment("eharris1/APLit_eharris1/Essay1_eharris1", "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']
|
||||||
#extra = t.reqAddStudentList(ar, "APLit_eharris1")
|
#extra = t.reqAddStudentList(ar, "APLit_eharris1")
|
||||||
#print(extra)
|
#print(extra)
|
||||||
|
|
7
eharris1/APLit_eharris1/BookReport/rubric.txt
Normal file
7
eharris1/APLit_eharris1/BookReport/rubric.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
kskskksks
|
||||||
|
kskskksks
|
||||||
|
kskskksks
|
||||||
|
kskskksks
|
||||||
|
kskskksks
|
||||||
|
kskskksks
|
||||||
|
kskskksks
|
0
eharris1/APLit_eharris1/BookReport/sample.txt
Normal file
0
eharris1/APLit_eharris1/BookReport/sample.txt
Normal file
0
eharris1/APLit_eharris1/Essay2/instruct.txt
Normal file
0
eharris1/APLit_eharris1/Essay2/instruct.txt
Normal file
130
skoolos.py
130
skoolos.py
|
@ -35,7 +35,7 @@ def main():
|
||||||
print("╚═════╝░╚═╝░░╚═╝░╚════╝░░╚════╝░╚══════╝ ░╚════╝░╚═════╝░")
|
print("╚═════╝░╚═╝░░╚═╝░╚════╝░░╚════╝░╚══════╝ ░╚════╝░╚═════╝░")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
if not os.path.exists(".profile"):
|
if not (os.path.exists(".sprofile") or os.path.exists(".tprofile")):
|
||||||
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)
|
||||||
|
@ -47,7 +47,10 @@ def main():
|
||||||
#webbrowser.open("http://127.0.0.1:8000/login", new=2)
|
#webbrowser.open("http://127.0.0.1:8000/login", new=2)
|
||||||
authenticate()
|
authenticate()
|
||||||
else:
|
else:
|
||||||
f = open('.profile','r')
|
try:
|
||||||
|
f = open('.tprofile','r')
|
||||||
|
except:
|
||||||
|
f = open('.sprofile','r')
|
||||||
data = json.loads(f.read())
|
data = json.loads(f.read())
|
||||||
f.close()
|
f.close()
|
||||||
PWD = data['password']
|
PWD = data['password']
|
||||||
|
@ -64,7 +67,7 @@ def main():
|
||||||
# pass
|
# pass
|
||||||
def studentCLI(user, password):
|
def studentCLI(user, password):
|
||||||
from CLI import student
|
from CLI import student
|
||||||
data = getUser(user, password)
|
data = getUser(user, password, 'student')
|
||||||
student = student.Student(data)
|
student = student.Student(data)
|
||||||
carray = student.sclass.split(",")
|
carray = student.sclass.split(",")
|
||||||
if(len(carray) == 1 and carray[0] == ""):
|
if(len(carray) == 1 and carray[0] == ""):
|
||||||
|
@ -80,24 +83,25 @@ def studentCLI(user, password):
|
||||||
'message': 'Select class: ',
|
'message': 'Select class: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
course = prompt(courses)
|
course = prompt(courses)['course']
|
||||||
|
print(course)
|
||||||
if course == "Exit SkoolOS":
|
if course == "Exit SkoolOS":
|
||||||
student.exitCLI()
|
student.exitCLI()
|
||||||
else:
|
else:
|
||||||
student.viewClass(course)
|
student.viewClass(course)
|
||||||
student.getAssignments(course, datetime.datetime.now())
|
student.getAssignments(course, 100)
|
||||||
|
|
||||||
def teacherCLI(user, password):
|
def teacherCLI(user, password):
|
||||||
from CLI import teacher
|
from CLI import teacher
|
||||||
data = getUser(user, password)
|
data = getUser(user, password, 'teacher')
|
||||||
|
print(data)
|
||||||
teacher = teacher.Teacher(data)
|
teacher = teacher.Teacher(data)
|
||||||
# 1. make a class
|
# 1. make a class
|
||||||
# 2. add studeents to an existing class
|
# 2. add studeents to an existing class
|
||||||
# 3. Get progress logs on a student
|
# 3. Get progress logs on a student
|
||||||
# 2. make an assignment for a class
|
# 2. make an assignment for a class
|
||||||
# 3. view student submissions for an assignment
|
# 3. view student submissions for an assignment
|
||||||
carray = teacher.sclass.split(",")
|
carray = teacher.classes
|
||||||
carray.remove("")
|
|
||||||
carray.append("Exit SkoolOS")
|
carray.append("Exit SkoolOS")
|
||||||
carray.append("Make New Class")
|
carray.append("Make New Class")
|
||||||
courses = [
|
courses = [
|
||||||
|
@ -108,7 +112,7 @@ def teacherCLI(user, password):
|
||||||
'message': 'Select class: ',
|
'message': 'Select class: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
course = prompt(courses)
|
course = prompt(courses)['course']
|
||||||
if course == "Exit SkoolOS":
|
if course == "Exit SkoolOS":
|
||||||
teacher.exitCLI()
|
teacher.exitCLI()
|
||||||
if course == "Make New Class":
|
if course == "Make New Class":
|
||||||
|
@ -119,7 +123,7 @@ def teacherCLI(user, password):
|
||||||
'message': 'Class Name: ',
|
'message': 'Class Name: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
cname = prompt(questions)
|
cname = prompt(questions)['cname']
|
||||||
teacher.makeClass(cname)
|
teacher.makeClass(cname)
|
||||||
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
||||||
questions = [
|
questions = [
|
||||||
|
@ -130,7 +134,7 @@ def teacherCLI(user, password):
|
||||||
'message': 'Add list of students (input path): ',
|
'message': 'Add list of students (input path): ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
choice = prompt(questions).split(")")
|
choice = prompt(questions)['students'].split(")")[0]
|
||||||
if("1" == choice):
|
if("1" == choice):
|
||||||
s = input("Student name: ")
|
s = input("Student name: ")
|
||||||
teacher.addStudent(s, cname)
|
teacher.addStudent(s, cname)
|
||||||
|
@ -140,8 +144,11 @@ def teacherCLI(user, password):
|
||||||
print(p + " does not exist.")
|
print(p + " does not exist.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Class: " + cname)
|
print("Class: " + course)
|
||||||
options = ['1) Add student', "2) Add assignment", "3) View student information"]
|
unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed']
|
||||||
|
for s in unconf:
|
||||||
|
teacher.addStudent()
|
||||||
|
options = ['1) Request Student', "2) Add assignment", "3) View student information"]
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
|
@ -150,23 +157,102 @@ def teacherCLI(user, password):
|
||||||
'message': 'Select option: ',
|
'message': 'Select option: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
option = prompt(questions)
|
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()
|
||||||
|
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)):
|
||||||
|
nlist.remove(n)
|
||||||
|
b = False
|
||||||
|
if(b):
|
||||||
|
tlist.append(n)
|
||||||
|
|
||||||
def getUser(ion_user, password):
|
|
||||||
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
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']
|
||||||
|
|
||||||
|
|
||||||
|
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))
|
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()
|
||||||
|
print(200)
|
||||||
return data
|
return data
|
||||||
elif(r.status_code == 404):
|
elif(r.status_code == 404):
|
||||||
return None
|
|
||||||
print("Make new account!")
|
print("Make new account!")
|
||||||
|
return None
|
||||||
elif(r.status_code == 403):
|
elif(r.status_code == 403):
|
||||||
return None
|
|
||||||
print("Invalid username/password")
|
print("Invalid username/password")
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
else:
|
||||||
print(r.status_code)
|
print(r.status_code)
|
||||||
|
return None
|
||||||
def patchDB(data, url):
|
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))
|
print("PATH:" + str(r.status_code))
|
||||||
|
@ -289,7 +375,7 @@ def authenticate():
|
||||||
'is_student':is_student,
|
'is_student':is_student,
|
||||||
'password':pwd,
|
'password':pwd,
|
||||||
}
|
}
|
||||||
profileFile = open(".profile", "w")
|
profileFile = open(".sprofile", "w")
|
||||||
profileFile.write(json.dumps(profile))
|
profileFile.write(json.dumps(profile))
|
||||||
profileFile.close()
|
profileFile.close()
|
||||||
|
|
||||||
|
@ -298,14 +384,12 @@ def authenticate():
|
||||||
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()
|
profile = r.json()
|
||||||
username = profile['ion_user']
|
username = profile['ion_user']
|
||||||
grade = profile['grade']
|
|
||||||
profile = {
|
profile = {
|
||||||
'username':username,
|
'username':username,
|
||||||
'grade':grade,
|
|
||||||
'is_student':is_student,
|
'is_student':is_student,
|
||||||
'password':pwd,
|
'password':pwd,
|
||||||
}
|
}
|
||||||
profileFile = open(".profile", "w")
|
profileFile = open(".tprofile", "w")
|
||||||
profileFile.write(json.dumps(profile))
|
profileFile.write(json.dumps(profile))
|
||||||
profileFile.close()
|
profileFile.close()
|
||||||
|
|
||||||
|
|
25
snew.py
25
snew.py
|
@ -83,18 +83,23 @@ class Students:
|
||||||
# }
|
# }
|
||||||
|
|
||||||
# c = Class.objects.get(name='Math5')
|
# c = Class.objects.get(name='Math5')
|
||||||
data = requests.get(url = "http://localhost:8000/api/classes/Math5", auth=('raffukhondaker','hackgroup1')).json()
|
# data = requests.get(url = "http://localhost:8000/api/classes/Math5", auth=('raffukhondaker','hackgroup1')).json()
|
||||||
|
|
||||||
r = requests.post(url = "http://localhost:8000/api/classes/", data={'name':'English11', 'teacher':'eharris1', 'owner':2}, auth=('raffukhondaker','hackgroup1'))
|
# r = requests.post(url = "http://localhost:8000/api/classes/", data={'name':'English11', 'teacher':'eharris1', 'owner':2}, auth=('raffukhondaker','hackgroup1'))
|
||||||
|
|
||||||
print("POST:" + str(r.json()))
|
# print("POST:" + str(r.json()))
|
||||||
|
# # print(r.json())
|
||||||
|
# # print(c.name)
|
||||||
|
# # c = {
|
||||||
|
# # 'classes':c
|
||||||
|
# # }
|
||||||
|
# # print(c)
|
||||||
|
# r = requests.patch(url = "http://localhost:8000/api/teachers/eharris1/", data={'classes':['English11']}, auth=('raffukhondaker','hackgroup1'))
|
||||||
# print(r.json())
|
# print(r.json())
|
||||||
# print(c.name)
|
import bgservice.bgservice as bg
|
||||||
# c = {
|
|
||||||
# 'classes':c
|
bg.watch_dir('2022rkhondak', 'eharris1')
|
||||||
# }
|
time.sleep(60)
|
||||||
# print(c)
|
bg.stop_watching()
|
||||||
r = requests.patch(url = "http://localhost:8000/api/teachers/eharris1/", data={'classes':['English11']}, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print(r.json())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
1
students.txt
Normal file
1
students.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
2022rkhondak
|
Loading…
Reference in New Issue
Block a user