Wed Jun 21 15:43:39 CEST 2023

This commit is contained in:
mnjx
2023-06-21 17:52:01 +02:00
12 changed files with 290 additions and 159 deletions
+100 -12
View File
@@ -6,18 +6,106 @@ from solenlib import schedule_week as sw
from solenlib import schedule_tdy_tmr as st
import sys
import getpass
import argparse
import datetime
if __name__ == "__main__":
user = str(input("Zadejte přihlašovací jméno: "))
try:
pwd = str(getpass.getpass("Zadejte heslo: "))
except:
pwd = str(input("Zadejte heslo: "))
parser = argparse.ArgumentParser(prog="ŠOLEn", description="ŠOLEn, an enhanced version of the ŠkolaOnLine online school system")
parser.add_argument("-t", "--today-tomorrow", action="store_true", help="Show the schedule for today and tomorrow")
parser.add_argument("-w", "--week", action="store_true", help="Show the schedule for this week")
parser.add_argument("-g", "--grades", action="store_true", help="Show the grades")
parser.add_argument("-u", "--username", action="store", default="", help="Provide the username for login")
parser.add_argument("-p", "--password", action="store", default="", help="Provide the password for login")
parser.add_argument("-l", "--local", action="store_true", help="Only fetch local files, don't connect to the internet")
parser.add_argument("-d", "--delete-local-files", action="store_true", help="Delete all local user data, including schedules, grades and user credentials")
parser.add_argument("-b", "--backup", action="store_true", help="Securely back up all user data and store them in a .tar.gz archive in the destination directory")
parser.add_argument("-D", "--backup-directory", action="store", help="Backup destination directory")
parser.add_argument("-P", "--backup-password", action="store", help="Backup password to encrypt the archive with")
parser.add_argument("-R", "--backup-restore", action="store", nargs=1, metavar="PATH", help="Specify the path to a .tar.gz archive that was earlier created with ŠOLEn to restore backed up user data")
args = parser.parse_args()
if args.delete_local_files:
try:
print("Removing all schedules and grades ...", end=" ")
os.system(f"rm -rf {os.environ['HOME']}/.local/lib/solendata/*.csv")
print("done")
print("Removing all user credentials ...", end=" ")
os.system(f"rm -rf {os.environ['HOME']}/.local/lib/solendata/shadow")
print("done")
print("All user data removed successfully")
sys.exit(0)
except:
print("Could not remove user data")
sys.exit(1)
elif args.backup:
try:
if not args.backup_directory or not args.backup_password:
print("-D, --backup-directory BACKUP-DIRECTORY and -P, --backup-password BACKUP-PASSWORD are required")
sys.exit(1)
else:
nowtime = str(datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
try:
print("Creating the backup archive ...", end=" ")
os.system(f"tar cf solen-backup-{nowtime} {os.path.abspath(args.backup-directory)}")
print("done")
print("Backup archive created successfully")
sys.exit(0)
except:
print("The 'tar' utility is not installed")
sys.exit(1)
except:
print("Could not backup user data")
sys.exit(1)
else:
if args.username:
user = str(args.username)
else:
user = str(input("Zadejte přihlašovací jméno: "))
if args.password:
pwd = str(args.password)
else:
try:
pwd = str(getpass.getpass("Zadejte heslo: "))
except:
pwd = str(input("Zadejte heslo: "))
if not nw.login(user, pwd):
print("LOGIN UNSUCCESSFULL")
sys.exit(1)
else:
sw.show_schedule()
st.show_schedule()
gr.show_grades()
if not nw.login(user, pwd):
print("Login unsuccessfull")
sys.exit(1)
else:
try:
if args.week:
if args.local:
sw.show_schedule(local=True)
else:
sw.show_schedule()
if args.today_tomorrow:
if args.local:
st.show_schedule(local=True)
else:
st.show_schedule()
if args.grades:
if args.local:
gr.show_grades(local=True)
else:
gr.show_grades()
if not args.grades and not args.today_tomorrow and not args.week:
if args.local:
sw.show_schedule(local=True)
st.show_schedule(local=True)
gr.show_grades(local=True)
else:
sw.show_schedule()
st.show_schedule()
gr.show_grades()
sys.exit(0)
except Exception as e:
print("Could not execute")
sys.exit(1)