mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
Added logs field
This commit is contained in:
parent
72af91c718
commit
ed275af4ea
|
@ -1 +0,0 @@
|
||||||
{"username": "2022rkhondak", "grade": 10, "is_student": true, "password": "hackgroup1"}
|
|
|
@ -1 +0,0 @@
|
||||||
{"username": "eharris1", "is_student": false, "password": "hackgroup1"}
|
|
1
2023rumareti
Submodule
1
2023rumareti
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit ca356ef8532873bf52ec67a647fbb91a25ca1cb7
|
|
@ -9,6 +9,7 @@ class Student(models.Model):
|
||||||
ion_user = models.CharField(max_length=100, primary_key=True)
|
ion_user = models.CharField(max_length=100, primary_key=True)
|
||||||
grade = models.IntegerField(default=0, blank=True)
|
grade = models.IntegerField(default=0, blank=True)
|
||||||
git=models.CharField(default="", max_length=100, blank=True)
|
git=models.CharField(default="", max_length=100, blank=True)
|
||||||
|
log = models.TextField(default="", blank=True)
|
||||||
repo=models.URLField(default="", blank=True)
|
repo=models.URLField(default="", blank=True)
|
||||||
classes=models.CharField(max_length=100, default="", blank=True)
|
classes=models.CharField(max_length=100, default="", blank=True)
|
||||||
added_to=models.CharField(max_length=100, default="", blank=True)
|
added_to=models.CharField(max_length=100, default="", blank=True)
|
||||||
|
|
|
@ -41,7 +41,7 @@ class StudentSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Student
|
model = Student
|
||||||
# fields = ['url','first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','Class','added_to','completed', 'repo','owner']
|
# fields = ['url','first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','Class','added_to','completed', 'repo','owner']
|
||||||
fields = ['url','grade', 'ion_user','git','user','classes','added_to','completed', 'repo']
|
fields = ['url','grade', 'log', 'ion_user','git','user','classes','added_to','completed', 'repo']
|
||||||
|
|
||||||
class TeacherSerializer(serializers.ModelSerializer):
|
class TeacherSerializer(serializers.ModelSerializer):
|
||||||
#classes = ClassSerializer(many=True, read_only=True,allow_null=True)
|
#classes = ClassSerializer(many=True, read_only=True,allow_null=True)
|
||||||
|
|
27224
bgservice/SkoolOS/logs/skoolos_06162020-211153
Normal file
27224
bgservice/SkoolOS/logs/skoolos_06162020-211153
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -3,6 +3,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
import pyinotify
|
import pyinotify
|
||||||
import checker
|
import checker
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class EventHandler(pyinotify.ProcessEvent):
|
class EventHandler(pyinotify.ProcessEvent):
|
||||||
|
@ -112,7 +113,7 @@ DIR = None
|
||||||
START_TIME = None
|
START_TIME = None
|
||||||
|
|
||||||
|
|
||||||
def watch_dir(watched_dir="/tmp", log_dir="/tmp/skooloslogs"):
|
def watch_dir(watched_dir=str(Path.home()), log_dir="SkoolOS/logs"):
|
||||||
"""
|
"""
|
||||||
Watches the specified directory for changes and outputs it in
|
Watches the specified directory for changes and outputs it in
|
||||||
human readable format to a log file in the specified log directory.
|
human readable format to a log file in the specified log directory.
|
||||||
|
@ -137,6 +138,7 @@ def watch_dir(watched_dir="/tmp", log_dir="/tmp/skooloslogs"):
|
||||||
NOTIFIER.start()
|
NOTIFIER.start()
|
||||||
sys.stdout = open("/dev/null", 'w')
|
sys.stdout = open("/dev/null", 'w')
|
||||||
wm.add_watch(watched_dir, mask, rec=True)
|
wm.add_watch(watched_dir, mask, rec=True)
|
||||||
|
time.sleep(1)
|
||||||
sys.stdout = logfile
|
sys.stdout = logfile
|
||||||
print("Start time: " +
|
print("Start time: " +
|
||||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()) + "\n")
|
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()) + "\n")
|
||||||
|
@ -162,4 +164,3 @@ def stop_watching():
|
||||||
+ "The paths to these files are listed below:\n")
|
+ "The paths to these files are listed below:\n")
|
||||||
print(*suspicious_files, sep='\n')
|
print(*suspicious_files, sep='\n')
|
||||||
sys.stdout = STDOUT
|
sys.stdout = STDOUT
|
||||||
print("Done watching.\n")
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
1
rushilwiz
Submodule
1
rushilwiz
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit b80d7ed56b7d649a74be4e7f906d26e7be43702d
|
780
skoolos.py
780
skoolos.py
|
@ -25,7 +25,12 @@ scope = ["read"]
|
||||||
USER = ""
|
USER = ""
|
||||||
PWD = ""
|
PWD = ""
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""
|
||||||
|
The Command Line Interface (CLI) for SkoolOS
|
||||||
|
Serves to allow both teachers and students to access the majority of the features of SkoolOS
|
||||||
|
"""
|
||||||
print("")
|
print("")
|
||||||
print("░██████╗██╗░░██╗░█████╗░░█████╗░██╗░░░░░ ░█████╗░░██████╗")
|
print("░██████╗██╗░░██╗░█████╗░░█████╗░██╗░░░░░ ░█████╗░░██████╗")
|
||||||
print("██╔════╝██║░██╔╝██╔══██╗██╔══██╗██║░░░░░ ██╔══██╗██╔════╝")
|
print("██╔════╝██║░██╔╝██╔══██╗██╔══██╗██║░░░░░ ██╔══██╗██╔════╝")
|
||||||
|
@ -35,291 +40,574 @@ 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)
|
||||||
except:
|
except:
|
||||||
print("Run Django server on http://127.0.0.1:8000/ before continuing")
|
print("Run Django server on http://127.0.0.1:8000/ before continuing")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
input("Welcome to SkoolOS. Press any key to create an account")
|
input("Welcome to SkoolOS. Press any key to create an account")
|
||||||
#webbrowser.open("http://127.0.0.1:8000/login", new=2)
|
# webbrowser.open("http://127.0.0.1:8000/login", new=2)
|
||||||
authenticate()
|
authenticate()
|
||||||
|
profiles = os.listdir()
|
||||||
|
users = []
|
||||||
|
info = []
|
||||||
|
count = 1
|
||||||
|
for i in range(len(profiles)):
|
||||||
|
p = profiles[i]
|
||||||
|
if 'profile' in p:
|
||||||
|
f = open(p, 'r')
|
||||||
|
d = json.loads(f.read())
|
||||||
|
f.close()
|
||||||
|
info.append(d)
|
||||||
|
users.append(str(count) + ") " + d['username'])
|
||||||
|
count = count + 1
|
||||||
|
users.append(str(count) + ") Make new user")
|
||||||
|
user = [
|
||||||
|
{
|
||||||
|
'type': 'list',
|
||||||
|
'name': 'user',
|
||||||
|
'choices': users,
|
||||||
|
'message': 'Select User: ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
u = int(prompt(user)['user'].split(")")[0]) - 1
|
||||||
|
if u + 1 == count:
|
||||||
|
authenticate()
|
||||||
|
return
|
||||||
|
data = info[u]
|
||||||
|
PWD = data['password']
|
||||||
|
USER = data['username']
|
||||||
|
print(data['username'])
|
||||||
|
if data['is_student']:
|
||||||
|
studentCLI(USER, PWD)
|
||||||
else:
|
else:
|
||||||
try:
|
teacherCLI(USER, PWD)
|
||||||
f = open('.tprofile','r')
|
|
||||||
except:
|
|
||||||
f = open('.sprofile','r')
|
#################################################################################################### STUDENT METHODS
|
||||||
data = json.loads(f.read())
|
|
||||||
f.close()
|
|
||||||
PWD = data['password']
|
|
||||||
USER = data['username']
|
|
||||||
print(data['username'])
|
|
||||||
if(data['is_student']):
|
|
||||||
studentCLI(USER, PWD)
|
|
||||||
else:
|
|
||||||
teacherCLI(USER, PWD)
|
|
||||||
|
|
||||||
|
|
||||||
# while True:
|
|
||||||
# pass
|
|
||||||
def studentCLI(user, password):
|
def studentCLI(user, password):
|
||||||
|
"""
|
||||||
|
The CLI for students to access
|
||||||
|
:param user: student username
|
||||||
|
:param password: student password
|
||||||
|
"""
|
||||||
from CLI import student
|
from CLI import student
|
||||||
data = getUser(user, password, 'student')
|
data = getUser(user, password, 'student')
|
||||||
student = student.Student(data)
|
student = student.Student(data, password)
|
||||||
|
student.update()
|
||||||
|
EXIT = False
|
||||||
|
while not EXIT:
|
||||||
|
course = chooseClassStudent(student)
|
||||||
|
if course == "Exit SkoolOS":
|
||||||
|
return
|
||||||
|
EXIT = classOptionsStudent(student, course)
|
||||||
|
|
||||||
|
|
||||||
|
# return class
|
||||||
|
def chooseClassStudent(student):
|
||||||
|
"""
|
||||||
|
Chooses a class for a student to view and work on
|
||||||
|
:param student: a student
|
||||||
|
:return: a course prompt
|
||||||
|
"""
|
||||||
carray = student.sclass.split(",")
|
carray = student.sclass.split(",")
|
||||||
if(len(carray) == 1 and carray[0] == ""):
|
if len(carray) == 1 and carray[0] == "":
|
||||||
|
carray.remove("")
|
||||||
print("No classes")
|
print("No classes")
|
||||||
return
|
|
||||||
|
|
||||||
carray.append("Exit SkoolOS")
|
carray.append("Exit SkoolOS")
|
||||||
courses = [
|
courses = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'name': 'course',
|
'name': 'course',
|
||||||
'choices':carray,
|
'choices': carray,
|
||||||
'message': 'Select class: ',
|
'message': 'Select class: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
course = prompt(courses)['course']
|
course = prompt(courses)['course']
|
||||||
print(course)
|
print(course)
|
||||||
if course == "Exit SkoolOS":
|
return course
|
||||||
student.exitCLI()
|
|
||||||
else:
|
|
||||||
student.viewClass(course)
|
|
||||||
student.getAssignments(course, 100)
|
|
||||||
|
|
||||||
|
|
||||||
|
def classOptionsStudent(student, course):
|
||||||
|
"""
|
||||||
|
Allows students to choose what they want to do related to a class
|
||||||
|
The student can save, exit, or go back
|
||||||
|
:param student: a student
|
||||||
|
:param course: a course
|
||||||
|
:return: True if exiting, False if going back
|
||||||
|
"""
|
||||||
|
student.viewClass(course)
|
||||||
|
student.getAssignments(course, 100)
|
||||||
|
choices = ["Save","Submit assignment","Back","Exit SkoolOS"]
|
||||||
|
options = [
|
||||||
|
{
|
||||||
|
'type': 'list',
|
||||||
|
'name': 'option',
|
||||||
|
'choices': choices,
|
||||||
|
'message': 'Select: ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
option = prompt(options)['option']
|
||||||
|
if option == "Save":
|
||||||
|
student.update()
|
||||||
|
print("Saved!")
|
||||||
|
classOptionsStudent(student, course)
|
||||||
|
if option == "Back":
|
||||||
|
student.exitCLI()
|
||||||
|
# dont exit cli
|
||||||
|
return False
|
||||||
|
if option == "Exit SkoolOS":
|
||||||
|
student.exitCLI()
|
||||||
|
# exit cli
|
||||||
|
return True
|
||||||
|
if(option == "Submit assignment"):
|
||||||
|
assignments = os.listdir(student.username)
|
||||||
|
tlist = []
|
||||||
|
b = True
|
||||||
|
for a in assignments:
|
||||||
|
oname = a + "_" + course
|
||||||
|
a = student.username + "/" + a
|
||||||
|
if(os.path.isdir(a) and not "." in a and not oname in student.completed):
|
||||||
|
tlist.append(a)
|
||||||
|
assignments = tlist
|
||||||
|
assignments.append("Back")
|
||||||
|
print(assignments)
|
||||||
|
|
||||||
|
options = [
|
||||||
|
{
|
||||||
|
'type': 'list',
|
||||||
|
'name': 'submit',
|
||||||
|
'choices':assignments,
|
||||||
|
'message': 'Select: ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
ass = prompt(options)['submit']
|
||||||
|
if(ass == "Back"):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
student.submit(course, ass)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
#################################################################################################### TEACHER METHODS
|
||||||
def teacherCLI(user, password):
|
def teacherCLI(user, password):
|
||||||
|
"""
|
||||||
|
The CLI for teachers to access
|
||||||
|
:param user: teachers username
|
||||||
|
:param password: teachers password
|
||||||
|
"""
|
||||||
from CLI import teacher
|
from CLI import teacher
|
||||||
data = getUser(user, password, 'teacher')
|
data = getUser(user, password, 'teacher')
|
||||||
print(data)
|
print(data)
|
||||||
teacher = teacher.Teacher(data)
|
teacher = teacher.Teacher(data, password)
|
||||||
|
EXIT = False
|
||||||
# 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.classes
|
while not EXIT:
|
||||||
carray.append("Exit SkoolOS")
|
# Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"
|
||||||
carray.append("Make New Class")
|
course = chooseGeneralTeacher(teacher)
|
||||||
courses = [
|
if course == "Exit SkoolOS":
|
||||||
{
|
EXIT = True
|
||||||
'type': 'list',
|
elif course == "Make New Class":
|
||||||
'name': 'course',
|
EXIT = makeClassTeacher(teacher)
|
||||||
'choices':carray,
|
# selected a class
|
||||||
'message': 'Select class: ',
|
else:
|
||||||
},
|
#Pull confirmed students directory
|
||||||
]
|
teacher.getStudents(course)
|
||||||
course = prompt(courses)['course']
|
option = classOptionsTeacher(teacher, course)
|
||||||
if course == "Exit SkoolOS":
|
if option == '1':
|
||||||
teacher.exitCLI()
|
EXIT = addStudentsTeacher(teacher, course)
|
||||||
if course == "Make New Class":
|
elif option == '2':
|
||||||
questions = [
|
EXIT = addAssignmentTeacher(teacher, course)
|
||||||
{
|
elif option == '3':
|
||||||
'type': 'input',
|
EXIT = viewStudentsTeacher(teacher, course)
|
||||||
'name': 'cname',
|
else:
|
||||||
'message': 'Class Name: ',
|
EXIT = True
|
||||||
},
|
|
||||||
]
|
|
||||||
cname = prompt(questions)['cname']
|
|
||||||
teacher.makeClass(cname)
|
|
||||||
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'list',
|
|
||||||
'choices':soption,
|
|
||||||
'name': 'students',
|
|
||||||
'message': 'Add list of students (input path): ',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
choice = prompt(questions)['students'].split(")")[0]
|
|
||||||
if("1" == choice):
|
|
||||||
s = input("Student name: ")
|
|
||||||
teacher.addStudent(s, cname)
|
|
||||||
if("2" == choice):
|
|
||||||
p = input("Relativee Path: ")
|
|
||||||
if(os.path.exists(p)):
|
|
||||||
print(p + " does not exist.")
|
|
||||||
|
|
||||||
else:
|
|
||||||
print("Class: " + course)
|
def chooseGeneralTeacher(teacher):
|
||||||
unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed']
|
carray = []
|
||||||
for s in unconf:
|
for c in teacher.classes:
|
||||||
teacher.addStudent()
|
carray.append(c)
|
||||||
options = ['1) Request Student', "2) Add assignment", "3) View student information"]
|
carray.append("Make New Class")
|
||||||
questions = [
|
carray.append("Exit SkoolOS")
|
||||||
|
courses = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'name': 'course',
|
'name': 'course',
|
||||||
'choices':options,
|
'choices': carray,
|
||||||
|
'message': 'Select class: ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
course = prompt(courses)['course']
|
||||||
|
return course
|
||||||
|
|
||||||
|
|
||||||
|
def makeClassTeacher(teacher):
|
||||||
|
questions = [
|
||||||
|
{
|
||||||
|
'type': 'input',
|
||||||
|
'name': 'cname',
|
||||||
|
'message': 'Class Name (Must be: <subject>_<ion_user>): ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
cname = prompt(questions)['cname']
|
||||||
|
print(cname)
|
||||||
|
while not ("_" + teacher.username) in cname:
|
||||||
|
print("Incorrect naming format")
|
||||||
|
questions = [
|
||||||
|
{
|
||||||
|
'type': 'input',
|
||||||
|
'name': 'cname',
|
||||||
|
'message': 'Class Name (Must be: <subject>_<ion_user>): ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
cname = prompt(questions)['cname']
|
||||||
|
|
||||||
|
teacher.makeClass(cname)
|
||||||
|
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
||||||
|
questions = [
|
||||||
|
{
|
||||||
|
'type': 'list',
|
||||||
|
'choices': soption,
|
||||||
|
'name': 'students',
|
||||||
|
'message': 'Add Students): ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
choice = prompt(questions)['students'].split(")")[0]
|
||||||
|
if "1" == choice:
|
||||||
|
s = input("Student name: ")
|
||||||
|
teacher.addStudent(s, cname)
|
||||||
|
if "2" == choice:
|
||||||
|
print("File must be .txt and have 1 student username per line")
|
||||||
|
path = input("Relative Path: ")
|
||||||
|
while not os.path.exists(path):
|
||||||
|
if path == 'N':
|
||||||
|
return True
|
||||||
|
print(path + " is not a valid path")
|
||||||
|
path = input("Enter file path ('N' to exit): ")
|
||||||
|
f = open(path, 'r')
|
||||||
|
students = f.read().splitlines()
|
||||||
|
teacher.reqAddStudentList(students, cname)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def classOptionsTeacher(teacher, course):
|
||||||
|
print("Class: " + course)
|
||||||
|
unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed']
|
||||||
|
for s in unconf:
|
||||||
|
teacher.addStudent(s, course)
|
||||||
|
options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"]
|
||||||
|
questions = [
|
||||||
|
{
|
||||||
|
'type': 'list',
|
||||||
|
'name': 'course',
|
||||||
|
'choices': options,
|
||||||
'message': 'Select option: ',
|
'message': 'Select option: ',
|
||||||
},
|
},
|
||||||
|
]
|
||||||
|
option = prompt(questions)['course'].split(")")[0]
|
||||||
|
return option
|
||||||
|
|
||||||
|
|
||||||
|
def addStudentsTeacher(teacher, course):
|
||||||
|
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
||||||
|
questions = [
|
||||||
|
{
|
||||||
|
'type': 'list',
|
||||||
|
'choices': soption,
|
||||||
|
'name': 'students',
|
||||||
|
'message': 'Add list of students (input path): ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
schoice = prompt(questions)['students'].split(")")[0]
|
||||||
|
if schoice == '1':
|
||||||
|
questions = [
|
||||||
|
{
|
||||||
|
'type': 'input',
|
||||||
|
'name': 'student',
|
||||||
|
'message': 'Student Name: ',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
option = prompt(questions)['course'].split(")")[0]
|
s = prompt(questions)['student']
|
||||||
if(option == '1'):
|
teacher.reqStudent(s, course)
|
||||||
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
return False
|
||||||
questions = [
|
if schoice == '2':
|
||||||
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'input',
|
||||||
'choices':soption,
|
'name': 'path',
|
||||||
'name': 'students',
|
'message': 'Path: ',
|
||||||
'message': 'Add list of students (input path): ',
|
},
|
||||||
},
|
]
|
||||||
]
|
path = prompt(questions)['path']
|
||||||
schoice = prompt(questions)['students'].split(")")[0]
|
while not os.path.exists(path):
|
||||||
if(schoice == '1'):
|
if path == 'N':
|
||||||
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)):
|
|
||||||
b = False
|
|
||||||
if(b):
|
|
||||||
tlist.append(n)
|
|
||||||
|
|
||||||
|
|
||||||
nlist = tlist
|
|
||||||
if(len(nlist) == 0):
|
|
||||||
print("No new assignments found")
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
questions = [
|
print(path + " is not a valid path")
|
||||||
{
|
path = input("Enter file path ('N' to exit): ")
|
||||||
'type': 'list',
|
f = open(path, 'r')
|
||||||
'choices':nlist,
|
students = f.read().splitlines()
|
||||||
'name': 'assignment',
|
teacher.reqAddStudentList(students, course)
|
||||||
'message': 'Select new assignment: ',
|
return False
|
||||||
},
|
else:
|
||||||
]
|
return True
|
||||||
ass = prompt(questions)['assignment']
|
|
||||||
apath = teacher.username + "/" + course + "/" + ass
|
|
||||||
|
def addAssignmentTeacher(teacher, course):
|
||||||
|
nlist = os.listdir(teacher.username + "/" + course)
|
||||||
|
alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments']
|
||||||
|
print(nlist)
|
||||||
|
tlist = []
|
||||||
|
b = True
|
||||||
|
for n in nlist:
|
||||||
|
b = True
|
||||||
|
print(teacher.username + "/" + course + "/" + n)
|
||||||
|
for a in alist:
|
||||||
|
if n in a or n == a:
|
||||||
|
# print("Assignments: " + n)
|
||||||
|
b = False
|
||||||
|
if not os.path.isdir(teacher.username + "/" + course + "/" + n):
|
||||||
|
b = False
|
||||||
|
if b:
|
||||||
|
tlist.append(n)
|
||||||
|
|
||||||
|
nlist = tlist
|
||||||
|
if len(nlist) == 0:
|
||||||
|
print("No new assignments found")
|
||||||
|
print(
|
||||||
|
"To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder")
|
||||||
|
return False
|
||||||
|
questions = [
|
||||||
|
{
|
||||||
|
'type': 'list',
|
||||||
|
'choices': nlist,
|
||||||
|
'name': 'assignment',
|
||||||
|
'message': 'Select new assignment: ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
ass = prompt(questions)['assignment']
|
||||||
|
apath = teacher.username + "/" + course + "/" + ass
|
||||||
|
due = input("Enter due date (Example: 2020-08-11 16:58): ")
|
||||||
|
due = due + ":33.383124"
|
||||||
|
due = due.strip()
|
||||||
|
f = False
|
||||||
|
while not f:
|
||||||
|
try:
|
||||||
|
datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
||||||
|
f = True
|
||||||
|
except:
|
||||||
|
print("Due-date format is incorrect.")
|
||||||
|
print(due)
|
||||||
due = input("Enter due date (Example: 2020-08-11 16:58): ")
|
due = input("Enter due date (Example: 2020-08-11 16:58): ")
|
||||||
due = due + ":00.000000"
|
due = due + ":33.383124"
|
||||||
due = due.strip()
|
teacher.addAssignment(apath, course, due)
|
||||||
teacher.addAssignment(apath, course, due)
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def viewStudentsTeacher(teacher, course):
|
||||||
|
data = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/classes/" + course)
|
||||||
|
students = data["confirmed"]
|
||||||
|
unconf = data['unconfirmed']
|
||||||
|
print("Studented in class: ")
|
||||||
|
for s in students:
|
||||||
|
print(s)
|
||||||
|
print("Requsted Students: ")
|
||||||
|
for s in unconf:
|
||||||
|
print(s)
|
||||||
|
student = input("View student (Enter student's ion username): ")
|
||||||
|
while((not student in str(data['confirmed'])) and (not student in str(data['unconfirmed']))):
|
||||||
|
print("Student not affiliated with class")
|
||||||
|
student = input("View student ('N' to exit): ")
|
||||||
|
if student == 'N':
|
||||||
|
return False
|
||||||
|
sinfo = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/")
|
||||||
|
pprint.pprint(sinfo)
|
||||||
|
print("Confirmed: " + str(student in str(data['confirmed'])))
|
||||||
|
if(student in str(data['confirmed'])):
|
||||||
|
path = teacher.username + "/Students/" + course + "/" + student
|
||||||
|
print(student + "'s work: " + path)
|
||||||
|
fin = sinfo['completed'].split(",")
|
||||||
|
alist = []
|
||||||
|
for f in fin:
|
||||||
|
if(course in f):
|
||||||
|
late = teacher.afterSubmit(course, f, student)
|
||||||
|
if(late):
|
||||||
|
s = f.split("_")[0] + " (LATE)"
|
||||||
|
else:
|
||||||
|
s = f.split("_")[0]
|
||||||
|
alist.append(s)
|
||||||
|
print("Has submitted: " + str(alist))
|
||||||
|
#Y/N
|
||||||
|
|
||||||
|
#put log stuff
|
||||||
|
|
||||||
|
############################################################################################################################################
|
||||||
|
|
||||||
|
|
||||||
def getUser(ion_user, password, utype):
|
def getUser(ion_user, password, utype):
|
||||||
if('student' in utype):
|
"""
|
||||||
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
Returns user information
|
||||||
else:
|
:param ion_user: user
|
||||||
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
:param password: user's password
|
||||||
r = requests.get(url = URL, auth=(ion_user,password))
|
:param utype: type of user (student or teacher
|
||||||
print(r.json())
|
:return: api user information
|
||||||
if(r.status_code == 200):
|
"""
|
||||||
data = r.json()
|
if 'student' in utype:
|
||||||
print(200)
|
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
||||||
return data
|
else:
|
||||||
elif(r.status_code == 404):
|
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
||||||
print("Make new account!")
|
print(URL)
|
||||||
return None
|
r = requests.get(url=URL, auth=(ion_user, password))
|
||||||
elif(r.status_code == 403):
|
print(r.json())
|
||||||
print("Invalid username/password")
|
if r.status_code == 200:
|
||||||
return None
|
data = r.json()
|
||||||
else:
|
print(200)
|
||||||
print(r.status_code)
|
return data
|
||||||
return None
|
elif r.status_code == 404:
|
||||||
def patchDB(data, url):
|
print("Make new account!")
|
||||||
r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
return None
|
||||||
|
elif r.status_code == 403:
|
||||||
|
print("Invalid username/password")
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
print(r.status_code)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def patchDB(USER, PWD, url, data):
|
||||||
|
"""
|
||||||
|
Sends a PATCH request to url
|
||||||
|
:param USER: username
|
||||||
|
:param PWD: password
|
||||||
|
:param url: URL for request
|
||||||
|
:param data: data to request
|
||||||
|
:return: json request response
|
||||||
|
"""
|
||||||
|
r = requests.patch(url=url, data=data, auth=(USER, PWD))
|
||||||
print("PATH:" + str(r.status_code))
|
print("PATH:" + str(r.status_code))
|
||||||
return(r.json())
|
return r.json()
|
||||||
|
|
||||||
def getDB(url):
|
|
||||||
r = requests.get(url = url, auth=('raffukhondaker','hackgroup1'))
|
def getDB(USER, PWD, url):
|
||||||
|
"""
|
||||||
|
Sends a GET request to url
|
||||||
|
:param USER: username
|
||||||
|
:param PWD: password
|
||||||
|
:param url: URL for request
|
||||||
|
:return: json request response
|
||||||
|
"""
|
||||||
|
r = requests.get(url=url, auth=(USER, PWD))
|
||||||
print("GET:" + str(r.status_code))
|
print("GET:" + str(r.status_code))
|
||||||
return(r.json())
|
return r.json()
|
||||||
|
|
||||||
def postDB(data, url):
|
|
||||||
r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
def postDB(USER, PWD, url, data):
|
||||||
|
"""
|
||||||
|
Sends a POST request to url
|
||||||
|
:param USER: username
|
||||||
|
:param PWD: password
|
||||||
|
:param url: URL for request
|
||||||
|
:param data: data to request
|
||||||
|
:return: json request response
|
||||||
|
"""
|
||||||
|
r = requests.post(url=url, data=data, auth=(USER, PWD))
|
||||||
print("POST:" + str(r.status_code))
|
print("POST:" + str(r.status_code))
|
||||||
return(r.json())
|
return r.json()
|
||||||
|
|
||||||
def putDB(data, url):
|
|
||||||
r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
def putDB(USER, PWD, url, data):
|
||||||
|
"""
|
||||||
|
Sends a PUT request to url
|
||||||
|
:param USER: username
|
||||||
|
:param PWD: password
|
||||||
|
:param url: URL for request
|
||||||
|
:param data: data to request
|
||||||
|
:return: json request response
|
||||||
|
"""
|
||||||
|
r = requests.put(url=url, data=data, auth=(USER, PWD))
|
||||||
print("PUT:" + str(r.status_code))
|
print("PUT:" + str(r.status_code))
|
||||||
return(r.json())
|
return r.json()
|
||||||
|
|
||||||
def delDB(url):
|
|
||||||
r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1'))
|
def delDB(USER, PWD, url):
|
||||||
|
"""
|
||||||
|
Sends a DELETE request to url
|
||||||
|
:param USER: username
|
||||||
|
:param PWD: password
|
||||||
|
:param url: URL for request
|
||||||
|
:return: json request response
|
||||||
|
"""
|
||||||
|
r = requests.delete(url=url, auth=(USER, PWD))
|
||||||
print("DELETE:" + str(r.status_code))
|
print("DELETE:" + str(r.status_code))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def makePass():
|
def makePass():
|
||||||
|
"""
|
||||||
|
Prompts the user to create a password
|
||||||
|
:return: the password
|
||||||
|
"""
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'password',
|
'type': 'password',
|
||||||
'name': 'pwd',
|
'name': 'pwd',
|
||||||
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
pwd = prompt(questions)['pwd']
|
pwd = prompt(questions)['pwd']
|
||||||
while(len(pwd) < 7):
|
while len(pwd) < 7:
|
||||||
print("Password too short (Must be over 6 characters)")
|
print("Password too short (Must be over 6 characters)")
|
||||||
pwd = prompt(questions)['pwd']
|
pwd = prompt(questions)['pwd']
|
||||||
conf = [
|
conf = [
|
||||||
{
|
{
|
||||||
'type': 'password',
|
'type': 'password',
|
||||||
'name': 'pwd',
|
'name': 'pwd',
|
||||||
'message': 'Re-enter password: ',
|
'message': 'Re-enter password: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
pwd2 = prompt(conf)['pwd']
|
pwd2 = prompt(conf)['pwd']
|
||||||
while(not pwd == pwd2):
|
while not pwd == pwd2:
|
||||||
print("Passwords do not match.")
|
print("Passwords do not match.")
|
||||||
pwd2 = prompt(conf)['pwd']
|
pwd2 = prompt(conf)['pwd']
|
||||||
else:
|
else:
|
||||||
print("PASSWORD SAVED")
|
print("PASSWORD SAVED")
|
||||||
return pwd
|
return pwd
|
||||||
|
|
||||||
|
|
||||||
def authenticate():
|
def authenticate():
|
||||||
|
"""
|
||||||
|
Authenticates the user via Ion OAuth
|
||||||
|
"""
|
||||||
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
|
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
|
||||||
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
|
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
|
||||||
|
import os
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
#Linux: chromdriver-linux
|
# Linux: chromdriver-linux
|
||||||
#Macos: chromdriver-mac
|
# Macos: chromdriver-mac
|
||||||
#Windows: chromdriver.exe
|
# Windows: chromdriver.exe
|
||||||
if('CLI' in os.getcwd()):
|
print("OS: ")
|
||||||
path = os.path.join(os.getcwd(), '../','chromedriver-mac')
|
print("MacOS")
|
||||||
else:
|
print("Linux")
|
||||||
path = os.path.join(os.getcwd(), 'chromedriver-mac')
|
|
||||||
|
system = input("Enter OS: ")
|
||||||
|
while(system.lower() != "linux" and system.lower() != "macos"):
|
||||||
|
print("Not valid OS")
|
||||||
|
system = input("Enter OS: ")
|
||||||
|
if(system.lower() == 'macos'):
|
||||||
|
path = os.path.join(os.getcwd(), 'chromedriver', 'chromedriver-mac')
|
||||||
|
if(system.lower() == 'linux'):
|
||||||
|
path = os.path.join(os.getcwd(), 'chromedriver', 'chromedriver-linux')
|
||||||
|
|
||||||
browser = webdriver.Chrome(path)
|
browser = webdriver.Chrome(path)
|
||||||
|
|
||||||
|
@ -330,7 +618,8 @@ def authenticate():
|
||||||
|
|
||||||
url = browser.current_url
|
url = browser.current_url
|
||||||
gets = url_decode(url.replace("http://localhost:8000/login/?", ""))
|
gets = url_decode(url.replace("http://localhost:8000/login/?", ""))
|
||||||
while "http://localhost:8000/login/?username=" not in browser.current_url and (not browser.current_url == "http://localhost:8000/"): #http://localhost:8000/
|
while "http://localhost:8000/login/?username=" not in browser.current_url and (
|
||||||
|
not browser.current_url == "http://localhost:8000/"): # http://localhost:8000/
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
|
|
||||||
url = browser.current_url
|
url = browser.current_url
|
||||||
|
@ -341,69 +630,76 @@ def authenticate():
|
||||||
# print("states good")
|
# print("states good")
|
||||||
browser.quit()
|
browser.quit()
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'input',
|
'type': 'input',
|
||||||
'name': 'username',
|
'name': 'username',
|
||||||
'message': 'Enter SkoolOS Username (Same as ION Username): ',
|
'message': 'Enter SkoolOS Username (Same as ION Username): ',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'type': 'password',
|
'type': 'password',
|
||||||
'name': 'pwd',
|
'name': 'pwd',
|
||||||
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
data =prompt(questions)
|
data = prompt(questions)
|
||||||
pwd = data['pwd']
|
pwd = data['pwd']
|
||||||
user = data['username']
|
user = data['username']
|
||||||
r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd))
|
r = requests.get(url="http://localhost:8000/api/", auth=(user, pwd))
|
||||||
while(r.status_code != 200):
|
while r.status_code != 200:
|
||||||
print("INCORRECT LOGIN CREDENTIALS")
|
print("INCORRECT LOGIN CREDENTIALS")
|
||||||
r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd))
|
r = requests.get(url="http://localhost:8000/api/", auth=(user, pwd))
|
||||||
data =prompt(questions)
|
data = prompt(questions)
|
||||||
pwd = data['pwd']
|
pwd = data['pwd']
|
||||||
user = data['username']
|
user = data['username']
|
||||||
print(r.status_code)
|
print(r.status_code)
|
||||||
r = requests.get(url = "http://localhost:8000/api/students/" + user + "/", auth=(user,pwd))
|
r = requests.get(url="http://localhost:8000/api/students/" + user + "/", auth=(user, pwd))
|
||||||
is_student = False
|
is_student = False
|
||||||
if(r.status_code == 200):
|
if r.status_code == 200:
|
||||||
is_student = True
|
is_student = True
|
||||||
print("Welcome, student " + user)
|
print("Welcome, student " + user)
|
||||||
r = requests.get(url = "http://localhost:8000/api/students/" + user + "/", auth=(user,pwd))
|
r = requests.get(url="http://localhost:8000/api/students/" + user + "/", auth=(user, pwd))
|
||||||
profile = r.json()
|
profile = r.json()
|
||||||
username = profile['ion_user']
|
username = profile['ion_user']
|
||||||
grade = profile['grade']
|
grade = profile['grade']
|
||||||
profile = {
|
profile = {
|
||||||
'username':username,
|
'username': username,
|
||||||
'grade':grade,
|
'grade': grade,
|
||||||
'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()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Welcome, teacher " + user)
|
print("Welcome, teacher " + user)
|
||||||
r = requests.get(url = "http://localhost:8000/api/teachers/" + user + "/", auth=(user,pwd))
|
r = requests.get(url="http://localhost:8000/api/teachers/" + user + "/", auth=(user, pwd))
|
||||||
profile = r.json()
|
profile = r.json()
|
||||||
username = profile['ion_user']
|
username = profile['ion_user']
|
||||||
profile = {
|
profile = {
|
||||||
'username':username,
|
'username': username,
|
||||||
'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():
|
||||||
|
"""
|
||||||
|
Creates a simple HTTP server for creating api requests from the CLI
|
||||||
|
"""
|
||||||
port = 8000
|
port = 8000
|
||||||
handler = http.server.SimpleHTTPRequestHandler
|
handler = http.server.SimpleHTTPRequestHandler
|
||||||
httpd = socketserver.TCPServer(("", port), handler)
|
httpd = socketserver.TCPServer(("", port), handler)
|
||||||
print("serving at port:" + str(port))
|
print("serving at port:" + str(port))
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
1
sstern1/Students/wow4_sstern1/2023rumareti
Submodule
1
sstern1/Students/wow4_sstern1/2023rumareti
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit ca356ef8532873bf52ec67a647fbb91a25ca1cb7
|
Loading…
Reference in New Issue
Block a user