Compare commits

..
1 Commits
Author SHA1 Message Date
Godnessli 2dc01ac099 make Auth 2026-10-18 22:23:08 +03:00
+51 -17
View File
@@ -30,9 +30,10 @@ class Person:
except FileNotFoundError:
return False
for acc in accounts:
if acc == account:
return True
if accounts != None:
for acc in accounts:
if acc == account:
return True
return False
@@ -57,28 +58,61 @@ class Person:
begin = account.find("@")
end = account.find(self.__DOMAIN)
accounts[account] = {
"nick" : account[begin:end],
"admin" : admin,
"u_count" : 0,
"w_count" : 0,
"ideas" : []
if accounts != None:
accs = dict(accounts)
else:
self.__create_file(account, admin)
new_acc = {
account: {
"nick" : account[begin:end],
"admin" : admin,
"u_count" : 0,
"w_count" : 0,
"ideas" : []
}
}
p_file.write(accounts)
if accounts != None:
accs.update(new_acc)
p_file.write(accs)
acc = accounts[account]
self.__nick = acc["nick"]
self.__admin = acc["admin"]
self.__unknown_counter = acc["u_count"]
self.__whether_counter = acc["w_count"]
self.__ideas = acc["ideas"]
self.__nick = new_acc["nick"]
self.__admin = new_acc["admin"]
self.__unknown_counter = new_acc["u_count"]
self.__whether_counter = new_acc["w_count"]
self.__ideas = new_acc["ideas"]
def __get_accounts(self) -> dict:
with open(self.__ACCOUNTS_FILE, 'r', encoding = 'utf-8') as p_file:
accounts = json.load(p_file)
accounts = None
try:
accounts = json.load(p_file)
except json.decoder.JSONDecodeError as e:
print(e)
p_file.close()
return accounts
def __create_file(self, name: str, admin: bool):
with open(self.__ACCOUNTS_FILE, 'w', encoding = 'utf-8') as p_file:
account = {
name : {
"nick" : self.__parse_name(name),
"admin" : False,
"u_count" : 0,
"w_count" : 0,
"ideas" : []
}
}
p_file.write(account)
def __parse_name(self, name: str) -> str:
begin = name.find("@")
end = name.find(self.__DOMAIN)
return name[begin:end]
tema = Person("@tema:godnessli")