capitalize global variable
This commit is contained in:
parent
975136a539
commit
54201439cb
16
auth.py
16
auth.py
|
@ -2,7 +2,7 @@ import json
|
|||
import sys
|
||||
from getpass import getpass
|
||||
|
||||
pwdb_path = 'pwdb.json'
|
||||
PWDB_PATH = 'pwdb.json'
|
||||
|
||||
def get_credentials():
|
||||
username = input('Enter your username: ')
|
||||
|
@ -16,26 +16,26 @@ def add_user(username, pwdb):
|
|||
pwdb[username] = input(f'Enter password for {username}: ')
|
||||
return pwdb
|
||||
|
||||
def read_pwdb(pwdb_path):
|
||||
def read_pwdb(PWDB_PATH):
|
||||
try:
|
||||
pwdb_file = open(pwdb_path, 'rt')
|
||||
pwdb_file = open(PWDB_PATH, 'rt')
|
||||
pwdb = json.load(pwdb_file)
|
||||
except Exception:
|
||||
pwdb = {}
|
||||
return pwdb
|
||||
|
||||
def write_pwdb(pwdb, pwdb_path):
|
||||
pwdb_file = open(pwdb_path, 'wt')
|
||||
def write_pwdb(pwdb, PWDB_PATH):
|
||||
pwdb_file = open(PWDB_PATH, 'wt')
|
||||
json.dump(pwdb, pwdb_file)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pwdb_path = 'pwdb.json'
|
||||
pwdb = read_pwdb(pwdb_path)
|
||||
PWDB_PATH = 'pwdb.json'
|
||||
pwdb = read_pwdb(PWDB_PATH)
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
pwdb = add_user(sys.argv[1], pwdb)
|
||||
write_pwdb(pwdb, pwdb_path)
|
||||
write_pwdb(pwdb, PWDB_PATH)
|
||||
else:
|
||||
username, password = get_credentials()
|
||||
if username not in pwdb:
|
||||
|
|
Loading…
Reference in a new issue