47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
import configparser
|
|
from typing import Optional
|
|
|
|
import requests
|
|
|
|
_c = configparser.ConfigParser()
|
|
_c.read("config.ini", "utf-8")
|
|
|
|
|
|
class _General:
|
|
token: str
|
|
sourceurl: Optional[str]
|
|
|
|
def __init__(self):
|
|
self.token = _c.get("General", "Token")
|
|
self.sourceurl = _c.get("General", "SourceUrl")
|
|
if not self.sourceurl.startswith("http://") and not self.sourceurl.startswith(
|
|
"https://"
|
|
):
|
|
self.sourceurl = None
|
|
|
|
|
|
class _App:
|
|
name: str
|
|
host: str
|
|
hostname: str
|
|
|
|
def __init__(self):
|
|
self.name = _c.get("App", "Name")
|
|
self.host = _c.get("App", "Host")
|
|
try:
|
|
response = requests.get(f"http://{self.host}/status.json", timeout=10)
|
|
if response.status_code != 200:
|
|
raise requests.exceptions.InvalidURL
|
|
except requests.exceptions.RequestException:
|
|
print("Unable validate App.Host in config.ini.")
|
|
exit(1)
|
|
self.hostname = _c.get("App", "HostName")
|
|
if not self.hostname:
|
|
self.hostname = self.host
|
|
self.protocol = "http"
|
|
if eval(_c.get("App", "PreferSecureProtocol")):
|
|
self.protocol = "https"
|
|
|
|
|
|
general = _General()
|
|
app = _App()
|