-
Notifications
You must be signed in to change notification settings - Fork 11
/
preparing_json.py
74 lines (58 loc) · 1.64 KB
/
preparing_json.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
import json
import os
import sys
import typing
try:
import k_amino.lib
except ModuleNotFoundError:
os.system(f"{sys.executable} -m pip install --upgrade k-amino.py")
print("reload is required after install k-amino.py")
exit(0)
################
savePath = "acc.json"
#############
def clear() -> None:
os.system('cls' if os.name=='nt' else 'clear')
info = (
"~ e: Exit\n"
"~ Press Enter to continue\n"
)
infoError = (
"~ Invalid account, do you want to save it? [Y/N]: "
)
clear()
print(
"save accounts in {}\n".upper().format(repr(savePath)) +
"necessary data:".capitalize(),
"email,".capitalize(), "password".capitalize()
)
def show_accounts() -> None:
print("\n~ Accounts: %d" % len(accounts))
accounts: typing.List[typing.Dict[str, str]] = []
if os.path.exists(savePath):
with open(savePath, 'r') as file:
accounts.extend(json.load(file))
while True:
show_accounts()
amino = k_amino.Client()
email = input("~ Email: ")
password = input("~ Password: ")
device = amino.deviceId
try:
amino.login(email, password)
except k_amino.lib.APIError as api:
print("~ error:", "({})".format(type(api).__name__), api.message)
if input(infoError).lower().strip() == "n":
continue
except k_amino.lib.AminoBaseException as exc:
print("~ error:", repr(exc))
if input(infoError).lower().strip() == "n":
continue
accounts.append(dict(
email=email,
password=password,
device=device
))
with open(savePath, 'w') as f:
json.dump(accounts, f, indent=4)
print('~ %r saved!' % email)