Skip to content

Commit d221bd2

Browse files
authored
Merge pull request #90 from prashere/feat/notes-app
Added notes app
2 parents aab8e9f + 6430690 commit d221bd2

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

N/notes-app/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Notes App
2+
3+
The **Notes App** is a simple command-line application for creating, viewing, and deleting text-based notes. This project allows you to manage your notes efficiently, all from your terminal.
4+
5+
## Features
6+
7+
- Create new notes with a title and content.
8+
- View the contents of existing notes.
9+
- Delete notes when they are no longer needed.
10+
11+
## Getting Started
12+
13+
### Prerequisites
14+
15+
To run this application, you'll need:
16+
17+
- Python (3.x recommended)
18+
19+
20+
### Usage
21+
22+
1. Run the Notes App:
23+
24+
```
25+
python notes-app.py
26+
```
27+
28+
2. Choose an option from the menu:
29+
- Enter `1` to create a new note.
30+
- Enter `2` to view an existing note.
31+
- Enter `3` to delete a note.
32+
- Enter `4` to exit the application.
33+
34+
3. Follow the on-screen prompts to perform your desired action.
35+

N/notes-app/functions.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import os
2+
3+
def create_file(title,content):
4+
"""
5+
This function creates a text file in the 'created-notes' directory with the given title and content.
6+
If the directory doesn't exist, it will be created.
7+
After creating the file, it prompts the user to print the content in the terminal.
8+
"""
9+
directory = 'N/notes-app/created-notes/'
10+
filename = title.lower() + ".txt"
11+
final_content = title.upper() + "\n\n" + content
12+
13+
# Ensuring that the directory exists and if it doesn't, creating it
14+
if not os.path.exists(directory):
15+
os.makedirs(directory)
16+
17+
# Combining the directory and filename to get the full file path
18+
file_path = os.path.join(directory, filename)
19+
20+
with open(file_path, 'w') as file:
21+
file.write(final_content)
22+
print("\nContent written successfully!! in " + filename+"\n")
23+
24+
to_print = input("SHOULD I PRINT IT IN THE TERMINAL?(Y for yes) ")
25+
if to_print=='Y' or to_print=='y':
26+
with open(file_path, 'r') as file:
27+
printing_content = file.read()
28+
print('\n'+'-'*50+'\n'+' '*20+'YOUR NOTE\n'+'-'*50)
29+
print(printing_content)
30+
31+
32+
def view_note(title):
33+
"""
34+
This function prints the contents of the text file with given title if the file exists.
35+
If file doesn't exists, it prints error message.
36+
"""
37+
filename = title.lower() + '.txt'
38+
directory = 'N/notes-app/created-notes/'
39+
try:
40+
with open(directory+filename, 'r') as file:
41+
print_contents = file.read()
42+
print('\n'+'-'*50+'\n'+' '*20+'YOUR NOTE\n'+'-'*50)
43+
print(print_contents)
44+
except FileNotFoundError:
45+
print('\n'+'-'*50+'\n'+' '*20+'ERROR\n'+'-'*50)
46+
print("No such text file available !!!")
47+
48+
49+
def delete_note(title):
50+
"""
51+
This function deletes the text file with given title if the file exists.
52+
If file doesn't exists, it prints error message.
53+
"""
54+
filename = title.lower() + '.txt'
55+
directory = 'N/notes-app/created-notes/'
56+
file_path = directory + filename
57+
if os.path.exists(file_path):
58+
os.remove(file_path) # Deleting the file
59+
print('\n'+'-'*50+'\n'+' '*20+'DELETED\n'+'-'*50)
60+
print(filename+ "successfully deleted !!!")
61+
62+
else:
63+
print('\n'+'-'*50+'\n'+' '*20+'ERROR\n'+'-'*50)
64+
print("No such text file available !!!")
65+
66+

N/notes-app/notes-app.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import sys
2+
from functions import *
3+
4+
# Initializing a flag variable for running of the application
5+
is_running = True
6+
7+
while is_running:
8+
# Displaying information on the screen
9+
print('\n')
10+
print(" "*20+"WELCOME TO NOTES APP")
11+
print('-'*50)
12+
print('Your options are:')
13+
print('1. Create a note')
14+
print('2. View a note')
15+
print('3. Delete a note')
16+
print('4. Exit \n')
17+
try:
18+
option = int(input("Select one option(1/2/3/4): "))
19+
if option == 1:
20+
title = input("Enter the tile for your note: ")
21+
content = input("Enter the content: \n")
22+
create_file(title,content)
23+
elif option == 2:
24+
title = input("Enter the tile of the note that you want to view: ")
25+
view_note(title)
26+
elif option == 3:
27+
title = input("Enter the tile of the note that you want to delete: ")
28+
delete_note(title)
29+
elif option == 4:
30+
sys.exit()
31+
except ValueError:
32+
print('\n'+'-'*50+'\n'+' '*20+'ERROR\n'+'-'*50)
33+
print("Enter 1/2/3/4 ")
34+
35+

0 commit comments

Comments
 (0)