From 589767dc95de5b5808a96dea33f50566db5b4016 Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya <2023rumareti@tjhsst.edu> Date: Tue, 2 Jun 2020 00:09:38 -0400 Subject: [PATCH 1/7] Started CLI --- CLI/skoolos.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 CLI/skoolos.py diff --git a/CLI/skoolos.py b/CLI/skoolos.py new file mode 100644 index 0000000..e69de29 From f529a98773804c4e757c6f869e3b537d3ffa3020 Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Thu, 4 Jun 2020 17:16:09 -0400 Subject: [PATCH 2/7] Added PyCharm to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b6e4761..2e3cb3b 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# PyCharm Files +.idea/ \ No newline at end of file From 291c9abb8e47cd974ec985d321d2580587226d1a Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Thu, 4 Jun 2020 17:17:54 -0400 Subject: [PATCH 3/7] working --- CLI/skoolos.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CLI/skoolos.py b/CLI/skoolos.py index e69de29..52a537a 100644 --- a/CLI/skoolos.py +++ b/CLI/skoolos.py @@ -0,0 +1,17 @@ +import sys +import click +from selenium import webdriver; + +PATH = "C:\Program Files (x86)\chromedriver.exe" + +print("") +print(" SSSSS CCCCC HH HH OOOOO OOOOO LL OOOOO SSSSS ") +print("SS CC C HH HH OO OO OO OO LL OO OO SS ") +print(" SSSSS CC HHHHHHH OO OO OO OO LL OO OO SSSSS ") +print(" SS CC C HH HH OO OO OO OO LL OO OO SS") +print(" SSSSS CCCCC HH HH OOOO0 OOOO0 LLLLLLL OOOO0 SSSSS ") +print("") + +driver = webdriver.Chrome(PATH) + +driver.get("") \ No newline at end of file From 24bbe6f466aa23ebaa19aad93b6650a9ac5593c0 Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Thu, 4 Jun 2020 22:57:45 -0400 Subject: [PATCH 4/7] working --- CLI/skoolos.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/CLI/skoolos.py b/CLI/skoolos.py index 52a537a..391b245 100644 --- a/CLI/skoolos.py +++ b/CLI/skoolos.py @@ -1,17 +1,30 @@ import sys import click from selenium import webdriver; +import os.path -PATH = "C:\Program Files (x86)\chromedriver.exe" -print("") -print(" SSSSS CCCCC HH HH OOOOO OOOOO LL OOOOO SSSSS ") -print("SS CC C HH HH OO OO OO OO LL OO OO SS ") -print(" SSSSS CC HHHHHHH OO OO OO OO LL OO OO SSSSS ") -print(" SS CC C HH HH OO OO OO OO LL OO OO SS") -print(" SSSSS CCCCC HH HH OOOO0 OOOO0 LLLLLLL OOOO0 SSSSS ") -print("") +def main(): + print("") + print(" SSSSS CCCCC HH HH OOOOO OOOOO LL OOOOO SSSSS ") + print("SS CC C HH HH OO OO OO OO LL OO OO SS ") + print(" SSSSS CC HHHHHHH OO OO OO OO LL OO OO SSSSS ") + print(" SS CC C HH HH OO OO OO OO LL OO OO SS") + print(" SSSSS CCCCC HH HH OOOO0 OOOO0 LLLLLLL OOOO0 SSSSS ") + print("") -driver = webdriver.Chrome(PATH) + if not os.path.exists(".profile"): + authenticate() + else: + print("welcome back") -driver.get("") \ No newline at end of file + + +def authenticate(): + file = open(".profile", "w") + file.write("Your Username") + file.close() + + +if __name__ == "__main__": + main() From 327c2ed79399957b82fed7c945cb074f5461452f Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Thu, 4 Jun 2020 23:04:16 -0400 Subject: [PATCH 5/7] alt version --- CLI/commands.py | 138 ++++++++++++++++++++++++++++++++++++++++++++++++ CLI/run.py | 22 ++++++++ CLI/users.json | 1 + 3 files changed, 161 insertions(+) create mode 100644 CLI/commands.py create mode 100644 CLI/run.py create mode 100644 CLI/users.json diff --git a/CLI/commands.py b/CLI/commands.py new file mode 100644 index 0000000..ebb7d88 --- /dev/null +++ b/CLI/commands.py @@ -0,0 +1,138 @@ +from __future__ import print_function, unicode_literals +from PyInquirer import prompt, print_json +import json +import os +import argparse + + +#already ccrerrated account through website, has to login +def update(): + #get data from database + return + +def yesorno(question): + questions = [ + { + 'type': 'input', + 'name': 'response', + 'message': question, + }, + ] + answers = prompt(questions) + if(answers["response"] == "y"): + return True + return False + +def login(): + #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(): + 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(): + 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 + for c in user["classes"]: + os.makedirs(c) + for a in user["classes"][c]: + os.makedirs(c + "/" + a) + +def start(): + 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)) + + \ No newline at end of file diff --git a/CLI/run.py b/CLI/run.py new file mode 100644 index 0000000..aca8859 --- /dev/null +++ b/CLI/run.py @@ -0,0 +1,22 @@ +from __future__ import print_function, unicode_literals +from PyInquirer import prompt, print_json +from commands import start, update +import argparse +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() + + + + + + diff --git a/CLI/users.json b/CLI/users.json new file mode 100644 index 0000000..bf1713e --- /dev/null +++ b/CLI/users.json @@ -0,0 +1 @@ +[{"first_name": "Raffu", "last_name": "Khondaker", "password": "password", "webmail": "2022rkhondak@tjhsst.edu", "classes": {"Math": ["week1_hw", "week2_hw", "week3_hw", "unit3_quiz"], "English": ["journal1", "journal2", "journal3"]}}] \ No newline at end of file From 18588c06f1603586e3badfeb8f4f7a6ff159a138 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Thu, 4 Jun 2020 23:05:54 -0400 Subject: [PATCH 6/7] Update commands.py --- CLI/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CLI/commands.py b/CLI/commands.py index ebb7d88..1780d32 100644 --- a/CLI/commands.py +++ b/CLI/commands.py @@ -118,9 +118,9 @@ def setup(user): #Read classes/assignenments and setup directory: #SkoolOS/Math/Week1 for c in user["classes"]: - os.makedirs(c) + os.makedirs("../" + c) for a in user["classes"][c]: - os.makedirs(c + "/" + a) + os.makedirs("../" + c + "/" + a) def start(): if(os.path.exists(".login.txt") == False): From 3b3d378f7f981107ca644a2dc8e1555baac46bca Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Fri, 5 Jun 2020 00:57:39 -0400 Subject: [PATCH 7/7] working --- CLI/skoolos.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/CLI/skoolos.py b/CLI/skoolos.py index 391b245..bf46ef4 100644 --- a/CLI/skoolos.py +++ b/CLI/skoolos.py @@ -1,7 +1,17 @@ import sys -import click +from urllib.parse import urlparse + +import requests +from requests_oauthlib import OAuth2Session from selenium import webdriver; import os.path +import time + +client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6' +client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY' +redirect_uri = 'http://localhost:8000/' +token_url = 'https://ion.tjhsst.edu/oauth/token/' +scope=["read"] def main(): @@ -16,14 +26,36 @@ def main(): if not os.path.exists(".profile"): authenticate() else: - print("welcome back") + print(open(".profile", "r").read()) def authenticate(): - file = open(".profile", "w") - file.write("Your Username") - file.close() + oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope) + authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/") + browser = webdriver.Chrome() + browser.get(authorization_url) + + while "http://localhost:8000/?code" not in browser.current_url: + time.sleep(0.25) + + code = urlparse(browser.current_url).query[5:] + browser.quit() + + payload = {'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri, 'client_id': client_id, + 'client_secret': client_secret, 'csrfmiddlewaretoken': state} + token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload).json() + print(token) + # headers = {'Authorization': f"Bearer {token['access_token']}"} + # + # # And finally get the user's profile! + # profile = requests.get("https://ion.tjhsst.edu/api/profile", headers=headers).json() + # username = profile['ion_username'] + # email = profile['tj_email'] + # first_name = profile['first_name'] + # last_name = profile['last_name'] + + #print(profile) if __name__ == "__main__":