init venv & began server connection & also debug menu
This commit is contained in:
92
CLI/Init.py
92
CLI/Init.py
@@ -1,7 +1,7 @@
|
||||
import configparser
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
#declare default vars
|
||||
class Config():
|
||||
|
||||
@@ -11,7 +11,9 @@ class Config():
|
||||
version = 01.02
|
||||
|
||||
class Server():
|
||||
host = "0.0.0.0" + ":5000"
|
||||
isReachable = False
|
||||
state = "Resolving IP"
|
||||
Icon = "🌐"
|
||||
if isReachable:
|
||||
Icon = "🌐"
|
||||
@@ -99,6 +101,23 @@ def loadConfig():
|
||||
except Exception as e:
|
||||
WarnMissingConfig(e)
|
||||
|
||||
def grabServerResolver():
|
||||
try:
|
||||
response = requests.get("https://kevinblog.sytes.net/APIS/test1.php")
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
server_ip = data.get("HostIp")
|
||||
Server.isReachable = False
|
||||
Server.host = server_ip
|
||||
return server_ip
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print("Error resolving a host, Considering service is offline.")
|
||||
Server.isReachable = False
|
||||
|
||||
pass
|
||||
|
||||
def checkConfig():
|
||||
if configPath.exists():
|
||||
print("The Config file exists.")
|
||||
@@ -108,6 +127,68 @@ def checkConfig():
|
||||
print("The file Config does not exist. - Creating")
|
||||
makeConfig()
|
||||
|
||||
|
||||
def debugMenu():
|
||||
class menuData():
|
||||
def mainMenu():
|
||||
Display.Clear()
|
||||
showIntroText()
|
||||
print(f"|[DBG] [{Server.Icon}]|")
|
||||
print("|1. Read Server Data |")
|
||||
print("|2. |")
|
||||
print("|3. |")
|
||||
print("|[e] Exit |")
|
||||
print("======================================================")
|
||||
|
||||
option = input(">> ")
|
||||
if option == "": menuData.mainMenu()
|
||||
match option:
|
||||
case "e":
|
||||
showMenu(1)
|
||||
return 0
|
||||
case "1":
|
||||
menuData.menuServerData()
|
||||
case _:
|
||||
menuData.mainMenu()
|
||||
|
||||
|
||||
|
||||
def menuServerData():
|
||||
Display.Clear()
|
||||
showIntroText()
|
||||
print(f"|[DBG: Login page] [{Server.Icon}]|")
|
||||
print(f"| IsReachable : {Server.isReachable}")
|
||||
print(f"| Host : {Server.host}")
|
||||
print(f"| State : {Server.state}")
|
||||
print("[e] Exit")
|
||||
print("======================================================")
|
||||
|
||||
option = input(">> ")
|
||||
if option == "": menuData.menuServerData()
|
||||
match option:
|
||||
case "e":
|
||||
showMenu(1)
|
||||
return 0
|
||||
case _:
|
||||
menuData.menuServerData()
|
||||
|
||||
menuData.mainMenu()
|
||||
option = input(">> ")
|
||||
if option == "": menuData.mainMenu()
|
||||
match option:
|
||||
case "e":
|
||||
showMenu(1)
|
||||
return 0
|
||||
case "1":
|
||||
menuData.menuServerData()
|
||||
case _:
|
||||
menuData.mainMenu()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def showMenu(menuID):
|
||||
Display.Clear()
|
||||
showIntroText()
|
||||
@@ -117,7 +198,7 @@ def showMenu(menuID):
|
||||
print("|[Main menu] |")
|
||||
print("|[1] Log in to tiropit | [2] Reset Data & Config |")
|
||||
print("|[3] Send / Get Request| [4] My Profile |")
|
||||
print("| |")
|
||||
print("|[5] Debug Data | |")
|
||||
print("|[e] Exit |")
|
||||
print("======================================================")
|
||||
option = input(">> ")
|
||||
@@ -128,6 +209,11 @@ def showMenu(menuID):
|
||||
match option:
|
||||
case "1":
|
||||
TiropitLogin()
|
||||
case "5":
|
||||
debugMenu()
|
||||
case "e":
|
||||
print("Cya!")
|
||||
exit();
|
||||
case _:
|
||||
showMenu(1)
|
||||
|
||||
@@ -144,6 +230,6 @@ def showMenu(menuID):
|
||||
|
||||
|
||||
#Begin
|
||||
|
||||
grabServerResolver()
|
||||
checkConfig()
|
||||
showMenu(1)
|
||||
|
||||
Reference in New Issue
Block a user