implement name-main trick

This commit is contained in:
Tiziano Zito 2024-08-26 12:08:10 +03:00
parent 095f4474b0
commit 65a910ff90

11
auth.py
View file

@ -25,13 +25,16 @@ def write_pwdb(pwdb, pwdb_path):
pwdb_file = open(pwdb_path, 'wt') pwdb_file = open(pwdb_path, 'wt')
json.dump(pwdb, pwdb_file) json.dump(pwdb, pwdb_file)
pwdb_path = 'pwdb.json'
pwdb = read_pwdb(pwdb_path)
if len(sys.argv) > 1: if __name__ == "__main__":
pwdb_path = 'pwdb.json'
pwdb = read_pwdb(pwdb_path)
if len(sys.argv) > 1:
pwdb = add_user(sys.argv[1], pwdb) pwdb = add_user(sys.argv[1], pwdb)
write_pwdb(pwdb, pwdb_path) write_pwdb(pwdb, pwdb_path)
else: else:
username, password = get_credentials() username, password = get_credentials()
if username not in pwdb: if username not in pwdb:
print('Wrong username!') print('Wrong username!')