-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
67 lines (56 loc) · 2.81 KB
/
setup.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
"""Author: Andrew Higgins
https://github.com/speckly
sucorn project setup, for first time users"""
import os
import getpass
import json
import venv
import subprocess
def _venv_req():
pip = f"{DIRECTORY}/venv/{'bin' if os.name != "nt" else 'Scripts'}/pip"
subprocess.check_call([pip, "install", "-r", "requirements.txt"],cwd=DIRECTORY)
DIRECTORY: str = os.path.dirname(os.path.realpath(__file__))
if not os.path.exists(f"{DIRECTORY}/.env"):
token: str = getpass.getpass("\n/.env\nInput Discord token (enter to skip): ")
if token.strip() != "":
with open(".env", "w", encoding="utf-8") as env_f:
env_f.write(f"TOKEN={token}")
print("Written Discord Token to .env")
if not os.path.exists(f"{DIRECTORY}/images"):
try:
print('Creating images folder')
os.makedirs(f"{DIRECTORY}/images")
except FileExistsError:
pass # Happens for symbolic links?
if not os.path.exists(f"{DIRECTORY}/utilities/reverse_api/.env"):
with open(f"{DIRECTORY}/utilities/reverse_api/.env", 'w', encoding="utf-8") as env_f:
general: str = getpass.getpass('Input general password, if all accounts share the same password (enter to skip): ')
env_f.write(f"GENERAL={general if general else ''}")
while True:
username = input("\n/utilities/reverse_api/.env\nInput Microsoft username (enter to skip): ")
if username.strip() == "":
break
password = getpass.getpass(f"Password for {username} (enter to skip): ")
if password.strip() == "":
break
pair: str = f"{username}={password}"
with open(f"{DIRECTORY}/utilities/reverse_api/.env", "a", encoding="utf-8") as env_f:
env_f.write(pair)
print(f"Written {pair}")
if not os.path.exists(f"{DIRECTORY}/utilities/reverse_api/new_prompt.txt"):
prompt: str = input("\n/reverse_api/new_prompt.txt\nInput prompt, can be changed later: ")
with open(f"{DIRECTORY}/utilities/reverse_api/new_prompt.txt", "w", encoding="utf-8") as f:
f.write(prompt)
if not os.path.exists(f"{DIRECTORY}/utilities/reverse_api/usernames.json"):
with open("./utilities/reverse_api/usernames.json", 'w', encoding="utf-8") as uFile:
usernames: dict = {"normal": [], "loaded": [], "unusable": [], "otp": []}
json.dump(usernames, uFile, indent=4)
print("initialised /utilities/reverse_api/usernames.json, use this file for loading of accounts in the normal key")
if input("Create venv? (Y): ").lower().strip() in ["", "y"]:
venv.create(f"{DIRECTORY}/venv", with_pip=True)
print("Creation complete")
if input("Install requirements in venv? (Y): ").lower().strip() in ["", "y"]:
_venv_req()
elif input("Install requirements without venv? (Y): ").lower().strip() in ["", "y"]:
os.system("pip install -r requirements.txt")
print("Setup complete!")