Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
add password read and write functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelDobariya38 committed Nov 7, 2023
1 parent 68a9f45 commit 6629787
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/app/commands.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import datahandler
from . import metadata

def quit_appplication():
Expand All @@ -12,13 +13,18 @@ def print_help_message():

def write_password():
website = input("Enter a website: ")
pasword = input("Enter a password: ")
print(website + " -> " + pasword)
password = input("Enter a password: ")
datahandler.save_data(website, password)
print("operation successfull!!!")
print()

def read_password():
pass
data_list = datahandler.load_data()
try:
for data_item in data_list:
print(f"{data_item[0]} - {data_item[1]}")
except IndexError as _:
raise Exception("data is corrupted!!")

def read_info():
path = metadata.RESOURCEDIR_PATH + "info.txt"
Expand Down
16 changes: 16 additions & 0 deletions src/app/datahandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from . import metadata

DATA_FILE = metadata.DATADIR_PATH + "data.txt"

def save_data(website, password):
data = metadata.DATA_SEPARATOR.join([website, password])
with open(DATA_FILE, "a") as f:
f.write(data + '\n')

def load_data():
data_list = []
with open(DATA_FILE) as f:
data = f.read()
for dataitem in data.split("\n"):
data_list.append(dataitem.split(metadata.DATA_SEPARATOR))
return data_list[:-1]
3 changes: 3 additions & 0 deletions src/app/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
# FilePath (Do Not Change this session, instead change above "Paths" session)
DATADIR_PATH = os.path.join(__file__, os.path.sep.join(__DATADIR)) + os.path.sep
RESOURCEDIR_PATH = os.path.join(__file__, os.path.sep.join(__RESOURCEDIR)) + os.path.sep

# App Configuration
DATA_SEPARATOR = " -> "

0 comments on commit 6629787

Please sign in to comment.