added settings file

This commit is contained in:
jpez 2022-04-22 11:11:06 +01:00
parent 6aa823f7a4
commit b285d60fc4
2 changed files with 55 additions and 10 deletions

View File

@ -1,34 +1,73 @@
import os
import subprocess as sp
from time import sleep
import json
import sys
accounts = ["username", "username"]
os.chdir("C://Users/joshu/Documents/Uni/CSY1026/scripts/")
json_file = open("settings.json", "r")
settings = json.load(json_file)
json_file.close()
accounts = settings["accounts"]
script_dir = settings["script_dir"]
password = settings["password"]
json_file = open("settings.json", "w")
try:
os.chdir(script_dir)
except FileNotFoundError:
print("\nYour script directory path doesn't exist!\n")
runFlag = True
def change_settings():
setting_choice = int(input("\nWhat would you like to do? \nCommands:\n1)Change accounts\n2)Change script dir path\n3)Quit\n>"))
if setting_choice == 1:
normal_account = input("\nWhat is your username for your normal account?\n>")
course_account = input("\nWhat is your username for your coursework account?\n>")
new_password = input("\nWhat is the password for these accounts (This should be your student ID)\n>")
settings["accounts"] = [normal_account, course_account]
settings["password"] = new_password
json.dump(settings, json_file)
elif setting_choice == 2:
new_dir = input("\nWhat is the path to your script directory?\n>")
settings["script_dir"] = new_dir
json.dump(settings, json_file)
else:
if setting_choice != 3:
print("\nIncorrect input!\n")
print("Returning to homepage...")
while runFlag:
account_choice = int(input("\nWhich account would you like to log into?\n1) Normal\n2) Coursework\n>"))
account_choice = int(input("\nWhich account would you like to log into?\n1)Normal\n2)Coursework\n3)Change Settings\n4)Quit\n>"))
if (account_choice == 1 or account_choice == 2):
runFlag = False
elif (account_choice == 3):
change_settings()
elif (account_choice == 4):
json.dump(settings, json_file)
json_file.close()
quit()
else:
print("\nIncorrect Input\n")
input("Press Enter to continue...\n")
print("\nHere are your available scripts:\n")
files = [f for f in os.listdir(".") if os.path.isfile(f)]
runFlag = True
while runFlag:
os.chdir("C://Users/joshu/Documents/Uni/CSY1026/scripts/")
os.chdir(script_dir)
print("\n")
print("\nHere are your available scripts:\n")
for i in range(0,len(files)):
print(files[i][:len(files[i])-4])
choice = input("\nWhat would you like to do? \nform: 'command file'\n\nCommands:\nedit\nedit folder\nrun\nquit\n> ")
choice = input("\nWhat would you like to do? \nform: 'command file'\n\nCommands:\nedit\nedit folder (open scripts folder)\nrun\nquit\n> ")
if (choice == "quit"):
runFlag = False
json.dump(settings, json_file)
json_file.close()
break
try:
split_choice = choice.rsplit(" ",1)
@ -47,9 +86,14 @@ while runFlag:
elif (command == "run"):
os.chdir("C://Oracle12c/")
run_time = sp.Popen(f"sqlplus.exe {accounts[account_choice-1]}@student/password", stdout=sp.PIPE, stdin=sp.PIPE, stderr=sp.PIPE)
print("\n"+run_time.communicate(f"@C://Users/joshu/Documents/Uni/CSY1026/scripts/{current_file}.sql\n".encode())[0].decode())
run_time = ""
run_time = sp.Popen(f"sqlplus.exe {accounts[account_choice-1]}@student/{password}", stdout=sp.PIPE, stdin=sp.PIPE, stderr=sp.PIPE)
s = run_time.communicate(f"@{script_dir}{current_file}.sql\n".encode())[0].decode()
s = s[s.find("options")+15:]
s = s[:s.find("SQL>")]
print("\n"+s)
input("Press Enter to continue...\n")
else:
print("\nIncorrect Input\n")
input("Press Enter to continue...\n")
input("Press Enter to continue...\n")

1
settings.json Normal file
View File

@ -0,0 +1 @@
{"accounts": ["CSY1026_109", "CSY1026_309"], "password": "21427656", "script_dir": "C:\\Users\\joshu\\Documents\\Uni\\CSY1026\\scripts\\"}