Files
TiropitLauncher/CLI/Init.py

150 lines
3.9 KiB
Python

import configparser
import os
from pathlib import Path
#declare default vars
class Config():
AccountKey = "NK"
AccountID = "NA"
version = 01.02
class Server():
isReachable = False
Icon = "🌐"
if isReachable:
Icon = "🌐"
else:
Icon = ""
#declare files
config = configparser.ConfigParser()
configPath = Path("Config.ini")
class Display():
def Clear():
os.system('cls' if os.name == 'nt' else 'clear')
def showIntroText():
print("Tiropit Launcher CLI - Release Branch")
print(f"[TCLI]=============[Select option]==============[{Config.version}]")
def WarnMissingConfig(ConfigError):
print(f"[⚠️ WARNING ⚠️] - Your config file is corrupt , something that has to do with {ConfigError}")
print("Program will exit before it crashes :)")
reset = input("It is recommended that you reset the app data (you will be logged out) y (reset) / n (exit)")
if reset == "y":
os.remove(configPath)
print("[⚠️ WARNING ⚠️] - Reset Done, Re-Open TiropitCLI")
exit(0)
def makeConfig():
config['DEFAULT'] = {'Version': Config.version}
config['ACCOUNT'] = {}
config['ACCOUNT']['KEY'] = "NK"
config['ACCOUNT']["ID"] = "NA"
with open('Config.ini', 'w') as configfile:
config.write(configfile)
def TiropitLogin():
class menuData():
def menuInstructions():
Display.Clear()
showIntroText()
print("|[About: Login Instructions] |")
print("|1. Enter your username & password |")
print("|2. Enter your pin (if you have) |")
print("|3. Save Login key (autologin) |")
print("|[e] Exit [Any] Login > |")
print("======================================================")
def menuUsername():
Display.Clear()
showIntroText()
print(f"|[LogIn: Login page] [{Server.Icon}]|")
print("| Enter your username |")
print("| |")
print("| |")
print("| |")
print("======================================================")
menuData.menuInstructions()
option = input(">> ")
match option:
case "e":
showMenu(1)
return 0
case _:
menuData.menuUsername()
def loadConfig():
try:
config.read(configPath)
Config.version = config["DEFAULT"]["Version"]
Config.AccountID = config["ACCOUNT"]["ID"]
Config.AccountID = config["ACCOUNT"]["KEY"]
except Exception as e:
WarnMissingConfig(e)
def checkConfig():
if configPath.exists():
print("The Config file exists.")
loadConfig()
else:
print("The file Config does not exist. - Creating")
makeConfig()
def showMenu(menuID):
Display.Clear()
showIntroText()
match menuID:
case 1:
print("|[Main menu] |")
print("|[1] Log in to tiropit | [2] Reset Data & Config |")
print("|[3] Send / Get Request| [4] My Profile |")
print("| |")
print("|[e] Exit |")
print("======================================================")
option = input(">> ")
if option == "": showMenu(1)
print(option)
match option:
case "1":
TiropitLogin()
case _:
showMenu(1)
pass
#Begin
checkConfig()
showMenu(1)