Skip to content

Commit 5a84192

Browse files
author
Tono_JIG
committed
Python Notes
1 parent 9fcfd67 commit 5a84192

17 files changed

+231
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Python_Notes
2+
3+
Python Console Notes APP with Authentication
4+
5+
It is a small project with a console user interface to practice with class modeling, MySQL database management, modularized in packages, etc.

db.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE DATABASE IF NOT EXISTS python_notes;
2+
use python_notes;
3+
4+
CREATE TABLE users(
5+
id int(25) auto_increment not null,
6+
name varchar(100),
7+
surnames varchar(255),
8+
email varchar(255) not null,
9+
password varchar(255) not null,
10+
fecha date not null,
11+
CONSTRAINT pk_users PRIMARY KEY (id),
12+
CONSTRAINT uq_email UNIQUE(email)
13+
)ENGINE=InnoDb;
14+
15+
CREATE TABLE notes(
16+
id int(25) auto_increment not null,
17+
user_id int(25) not null,
18+
title varchar(255) not null,
19+
description MEDIUMTEXT,
20+
date date not null,
21+
CONSTRAINT pk_notes PRIMARY KEY(id),
22+
CONSTRAINT fk_user_note FOREIGN KEY (user_id) REFERENCES users(id)
23+
)ENGINE=InnoDb;

main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from users import actions
2+
3+
print("""
4+
Acciones disponibles:
5+
- registro
6+
- login
7+
""")
8+
9+
actions = actions.Actions()
10+
11+
selection = input("¿Qué quieres hacer?: ")
12+
13+
if selection == "registro":
14+
actions.register()
15+
16+
elif selection == "login":
17+
actions.login()

notes/__init__.py

Whitespace-only changes.
143 Bytes
Binary file not shown.
1.67 KB
Binary file not shown.
1.32 KB
Binary file not shown.

notes/actions.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import notes.note as model
2+
3+
4+
class Actions:
5+
6+
def create(self, user):
7+
print(f"\nOk, {user[1]}, vamos a crear una nueva nota...")
8+
title = input("Introduce el título el título de la nota: ")
9+
description = input("Introduce el título la descripción de la nota: ")
10+
11+
note = model.Note(user[0], title, description)
12+
save = note.save()
13+
14+
if save[0] >= 1:
15+
print(f"\nLa nota '{note.title}' ha sido guardada!")
16+
else:
17+
print(f"\nNo se ha podido guardar la nota, {user[1]}.")
18+
19+
def list(sef, user):
20+
print(f"\nOk {user[1]}, estas son tus notas:")
21+
note = model.Note(user[0])
22+
notes = note.list()
23+
for note in notes:
24+
print("\n*************************************")
25+
print(f"Título: {note[2]}")
26+
print(f"Descripción: {note[3]}")
27+
print("*************************************")
28+
29+
def delete(self, user):
30+
print(f"\nOk {user[1]}, vamos a borrar una nota!")
31+
title = input("Introduce el título de la nota a borrar: ")
32+
note = model.Note(user[0], title)
33+
delete = note.delete()
34+
if delete[0] >= 1:
35+
print(f"Nota '{note.title}' borrada!")
36+
else:
37+
print("No se ha borrado la nota.")

notes/note.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import users.db_conection as connection
2+
3+
connect = connection.connect()
4+
database = connect[0]
5+
cursor = connect[1]
6+
7+
8+
class Note:
9+
10+
def __init__(self, user_id, title="", description=""):
11+
self.user_id = user_id
12+
self.title = title
13+
self.description = description
14+
15+
def save(self):
16+
sql = "INSERT INTO notes VALUES(null,%s,%s,%s,NOW())"
17+
note = (self.user_id, self.title, self.description)
18+
cursor.execute(sql, note)
19+
database.commit()
20+
return [cursor.rowcount, self]
21+
22+
def list(self):
23+
sql = f"SELECT * FROM notes WHERE user_id = {self.user_id}"
24+
cursor.execute(sql)
25+
result = cursor.fetchall()
26+
return result
27+
28+
def delete(self):
29+
sql = f"DELETE FROM notes WHERE user_id = {self.user_id} AND title LIKE '%{self.title}%'"
30+
cursor.execute(sql)
31+
database.commit()
32+
return [cursor.rowcount, self]

users/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)