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

Commit

Permalink
add typehint
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelDobariya38 committed Nov 7, 2023
1 parent 19103b8 commit 3e1dea3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
11 changes: 6 additions & 5 deletions src/app/commands.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
from . import datahandler
from . import metadata

def quit_appplication():
def quit_appplication() -> None:
print("Quiting the Application....")

def print_help_message():
def print_help_message() -> None:
print("Here are valid commands:")
print(" - \"quit\" or \"exit\": for quiting the app")
print(" - \"read\" or \"load\": for reading or loading the existing passwords")
print(" - \"write\" or \"save\": for writing or saveing the new passwords")
print()

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

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

def read_info():
def read_info() -> None:
path = metadata.RESOURCEDIR_PATH + "info.txt"
with open(path) as f:
data = f.read()
Expand Down
8 changes: 5 additions & 3 deletions src/app/datahandler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from . import metadata

DATA_FILE = metadata.DATADIR_PATH + "data.txt"
from typing import List

def save_data(website, password):
DATA_FILE: str = metadata.DATADIR_PATH + "data.txt"

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

def load_data():
def load_data() -> List[str]:
data_list = []
with open(DATA_FILE) as f:
data = f.read()
Expand Down
10 changes: 5 additions & 5 deletions src/app/eventhandler.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from . import commands

def handle_quit_event():
def handle_quit_event() -> None:
commands.quit_appplication()

def handle_help_event():
def handle_help_event() -> None:
commands.print_help_message()

def handle_write_password_event():
def handle_write_password_event() -> None:
commands.write_password()

def handle_read_password_event():
def handle_read_password_event() -> None:
commands.read_password()

def handle_info_event():
def handle_info_event() -> None:
commands.read_info()
18 changes: 9 additions & 9 deletions src/app/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import os

# App
NAME = "Smart Manager"
VERSION = "0.1.0-alpha"
WEBSITE = "https://jeeldobariya38.github.io/Smart-Manager/"
REPO = "https://github.com/JeelDobariya38/Smart-Manager"
NAME: str = "Smart Manager"
VERSION: str = "0.1.0-alpha"
WEBSITE: str = "https://jeeldobariya38.github.io/Smart-Manager/"
REPO: str = "https://github.com/JeelDobariya38/Smart-Manager"

# Paths (all path are relative to this file)
__DATADIR = ["..", "..", "..", "data"]
__RESOURCEDIR = ["..", "..", "..", "resource"]
__DATADIR: str = ["..", "..", "..", "data"]
__RESOURCEDIR: str = ["..", "..", "..", "resource"]

# 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
DATADIR_PATH: str = os.path.join(__file__, os.path.sep.join(__DATADIR)) + os.path.sep
RESOURCEDIR_PATH: str = os.path.join(__file__, os.path.sep.join(__RESOURCEDIR)) + os.path.sep

# App Configuration
DATA_SEPARATOR = " -> "
DATA_SEPARATOR: str = " -> "

0 comments on commit 3e1dea3

Please sign in to comment.