-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
69 lines (58 loc) · 2.14 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
import os
import sys
def pip_install(name: str):
os.system(
f'{"py" if os.name == "nt" else "python3"} -m pip install -U {name}')
class Database:
config_filename = os.path.join(os.getcwd(), "config.json")
if not(os.path.isfile(config_filename)):
with open(config_filename, "w", encoding="utf-8") as _file:
_file.write(
'{\n\t"username": "",\n\t"password": ""\n\t"web": {\n\t\t"host": "0.0.0.0",\n\t\t"port": 8080,\n\t\t"debug": false\n\t}\n}')
with open(config_filename, "r", encoding="utf-8") as _file:
_data = json.load(_file)
USERNAME = _data["username"].strip()
PASSWORD = _data["password"].strip()
# https://github.com/hirusha-adi/InstaStalker/issues/3
if isinstance(USERNAME, str) and len(USERNAME) == 0:
username_file = os.path.join(os.getcwd(), "username.txt")
if os.path.isfile(username_file):
with open(username_file, "r", encoding="utf-8") as _uname_file:
USERNAME = _uname_file.read().strip()
else:
USERNAME = None
if isinstance(PASSWORD, str) and len(PASSWORD) == 0:
password_file = os.path.join(os.getcwd(), "password.txt")
if os.path.isfile(password_file):
with open(password_file, "r", encoding="utf-8") as _passwd_file:
PASSWORD = _uname_file.read().strip()
else:
PASSWORD = None
try:
HOST: str = _data["web"]["host"]
if not(len(str(HOST).split(".")) == 4):
HOST: str = "0.0.0.0"
except KeyError:
HOST: str = "0.0.0.0"
try:
PORT = _data["web"]["port"]
try:
PORT: int = int(PORT)
except ValueError:
PORT: int = 8080
except KeyError:
PORT: int = 8080
try:
DEBUG = _data["web"]["debug"]
if isinstance(DEBUG, str):
if DEBUG.lower() in ("true", "t", "yes", "y"):
DEBUG: bool = True
else:
DEBUG: bool = False
elif isinstance(DEBUG, bool):
pass
else:
DEBUG: bool = False
except KeyError:
DEBUG: bool = False