-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
160 lines (134 loc) · 4.45 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import os
import json
from tabulate import tabulate
# Use this to create exe
# python -m PyInstaller --onefile main.py
# CRUD
def account_create(username, password, riot_id, region, banned):
global accounts
account = [username, password, riot_id, region, banned]
accounts.append(account)
save_db()
def accounts_read():
global accounts
accounts_formated = []
for index, account in enumerate(accounts):
accounts_formated.append([index, account[0], account[1], account[2], account[3], account[4]])
headers = ["id", "username", "password", "riot id", "region", "banned"]
if len(accounts) == 0:
print("No accounts to show")
else:
print(tabulate(accounts_formated, headers=headers, tablefmt="grid"))
def account_get(account_id):
global accounts
account = accounts[account_id]
paste_to_clipboard(f"{account[0]}, {account[1]}")
def account_update(account_id, username="", password="", riot_id="", region="", banned=False):
global accounts
account_edit = accounts[account_id]
if username != "":
account_edit[0] = username
if password != "":
account_edit[1] = password
if riot_id != "":
account_edit[2] = riot_id
if region != "":
account_edit[3] = region
if banned != account_edit[4]:
account_edit[4] = banned
accounts[account_id] = account_edit
save_db()
def account_delete(account_id):
global accounts
del accounts[account_id]
save_db()
# Database actions
def save_db():
global accounts
dump = json.dumps(accounts, indent=4)
f = open(FILE, "w")
f.write(dump)
f.close
def load_db():
if os.path.exists(FILE):
with open(FILE, "r") as f:
undump = json.load(f)
global accounts
accounts = undump
f.close()
else:
save_db()
# Constants and useful functions
FILE = "db.json"
def paste_to_clipboard(account):
command = "echo | set /p null=" + account.strip() + "| clip"
os.system(command)
def clear():
os.system('cls')
# Account list structure: username, password, riotID, banned status
accounts = []
# Startup actions
load_db()
# GUI/CLI
while True:
clear()
print("1. create account\n2. read all accounts\n3. get account\n4. update account\n5. delete account\nuse 0 to exit")
option = input()
if option == "0":
save_db()
break
elif option == "1":
clear()
username = input("insert username: ")
password = input("insert password: ")
riot_id = input("insert riot id: ")
region = input("insert region: ")
banned = input("is it banned? (y/n): ")
if banned == "y":
banned = True
else:
banned = False
account_create(username, password, riot_id, region, banned)
input("account created, press enter to return...")
elif option == "2":
clear()
accounts_read()
input("press enter to return...")
elif option == "3":
clear()
accounts_read()
try:
account_id = int(input("insert account id: "))
account_get(account_id)
input("account copied, press enter to return...")
except (ValueError, IndexError):
input("wrong input, press enter to return...")
elif option == "4":
clear()
accounts_read()
try:
account_id = int(input("insert id:"))
username = input("insert new username (enter to skip) ")
password = input("insert new password (enter to skip) ")
riot_id = input("insert new riot id (enter to skip) ")
region = input("insert new region (enter to skip) ")
banned = input("banned? (y/n) (enter to skip) ")
if banned == "y":
banned = True
else:
banned = False
account_update(account_id, username, password, riot_id, region, banned)
input("account updated, press enter to return...")
except (ValueError, IndexError):
input("wrong input, press enter to return...")
elif option == "5":
clear()
accounts_read()
try:
account_id = int(input("insert account id: "))
account_delete(account_id)
input("account deleted, press enter to return...")
except (ValueError, IndexError):
input("wrong input, press enter to return...")
else:
print("not in range")