Skip to content

Commit 2eab7d6

Browse files
committed
new project 22-Projects
1 parent 168ca21 commit 2eab7d6

3 files changed

Lines changed: 74 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.vscode
1+
.vscode
2+
22-Projects/noteapp/env

22-Projects/noteapp/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DB_URL="mongodb+srv://<your_username>:<your_passwor>@cluster0.bjqjx.mongodb.net/"

22-Projects/noteapp/noteapp.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import os
2+
from dotenv import load_dotenv
3+
import pymongo
4+
from bson import ObjectId
5+
6+
load_dotenv()
7+
DB_URL=os.getenv("DB_URL")
8+
9+
client = pymongo.MongoClient(DB_URL)
10+
11+
db = client["noteapp"]
12+
notes_col = db["notes"]
13+
# note = {
14+
# "title":"This is the title of note",
15+
# "desc":"This is descriptiong of note"
16+
# }
17+
# res = notes_col.insert_one(note)
18+
# print(res)
19+
def show_notes():
20+
notes = notes_col.find()
21+
if notes:
22+
for note in notes:
23+
print(f"id : {note["_id"]}")
24+
print(f"title : {note["title"]}")
25+
print(f"desc : {note["desc"]}")
26+
else:
27+
print("No notes found.")
28+
29+
def add_note():
30+
title = input("Enter title of note: ")
31+
desc = input("Enter description of note: ")
32+
notes_col.insert_one({"title": title,"desc": desc})
33+
print("Note added successfully.")
34+
35+
def update_note():
36+
id = input("Enter the id of note: ")
37+
new_title = input("Enter new title of note: ")
38+
new_desc = input("Enter new description of note: ")
39+
notes_col.update_one({"_id":ObjectId(id)},{"$set": {"title": new_title, "desc": new_desc}})
40+
print("Note updated successfully.")
41+
42+
def delete_note():
43+
id = input("Enter the id of note: ")
44+
notes_col.delete_one({"_id":ObjectId(id)})
45+
print("Note deleted successfully.")
46+
47+
def main():
48+
while True:
49+
print("\nNote Taking App with Database\n")
50+
print("1. Show Notes")
51+
print("2. Add Note")
52+
print("3. Update Note")
53+
print("4. Delete Note")
54+
print("5. Exit")
55+
56+
choice = input("select options (1/2/3/4/5): ")
57+
if choice == "1":
58+
show_notes()
59+
elif choice == "2":
60+
add_note()
61+
elif choice == "3":
62+
update_note()
63+
elif choice == "4":
64+
delete_note()
65+
elif choice == "5":
66+
print("Thanks for using this app")
67+
break
68+
else:
69+
print("Please select valid option.")
70+
if __name__ == "__main__":
71+
main()

0 commit comments

Comments
 (0)