From 787f3458b404f31cc2cb6302c83cd5ee55454af3 Mon Sep 17 00:00:00 2001 From: Rainy21 Date: Fri, 20 Feb 2026 22:46:33 -0500 Subject: [PATCH] create a db (not fully finish) --- README.md | 20 +++++++++++- app.py | 27 ++++++++++++++++ db/BookandMovieDB.py | 76 ++++++++++++++++++++++++++++++++++++++++++++ main.html | 26 +++++++++++---- template/card.html | 0 5 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 app.py create mode 100644 db/BookandMovieDB.py create mode 100644 template/card.html diff --git a/README.md b/README.md index f7ae440..5ac20a6 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -# Front-end-Design-Project +# Media library tracker +a lightweight web application to manage and track progress for Books and TV Shows using a unified SQLite database + +# Feature +- Unified Database: One central hub for all media types using SQL table inheritance. + +- Progress Tracking: Track pages read for books and episodes watched for shows. + +- Dynamic UI: Responsive HTML info cards that change color/content based on media type. + +- SQLite Backend: No complex database setup required—just a single .db file. + +# Tech Stack + + Language: Python 3.x + + Database: SQLite3 + + Frontend: HTML5, CSS3 (Flexbox/Grid) diff --git a/app.py b/app.py new file mode 100644 index 0000000..e2de1a5 --- /dev/null +++ b/app.py @@ -0,0 +1,27 @@ +from flask import Flask , render_template +import sqlite3 + +app = Flask(__name__) + +def get_db_connect(): + conn = sqlite3.connection("./db/my_library.db") + conn.row_factory = sqlite3.Row + return conn + +@app.route('/') +def index(): + conn = sqlite3.connection("./db/my_library.db") + query = """ + SELECT m.title, m.type, m.release_year, m.rating, + b.author, s.network + FROM media m + LEFT JOIN books b on m.id = b.books_id + LEFT JOIN shows s on m.id = s.shows_id + """ + items = conn.execute(query).fetchall() + conn.close() + +if __name__ == '__main__': + app.run(debug = True) + + diff --git a/db/BookandMovieDB.py b/db/BookandMovieDB.py new file mode 100644 index 0000000..a00d03d --- /dev/null +++ b/db/BookandMovieDB.py @@ -0,0 +1,76 @@ +import sqlite3 + +def init_db(): + conn = sqlite3.connect('my_library.db') + cursor = conn.cursor() + + cursor.executescript(''' + CREATE A TABLE IF NOT EXISTS media( + id INTEGER PRIMARY KEY AUTOINCREMENT, + title TEXT NOT NULL, + type TEXT CHECK(type IN ('Book', 'Show')), + release_year INTEGER + ); + + CREATE A TABLE IF NOT EXISTS books( + book_id INTEGER PRIMARY KEY, + author TEXT, + page INTEGER, + FOREIGN KEY (book_id) REFERENCES media (id) + ); + + CREATE A TABLE IF NOT EXISTS shows( + show_id INTEGER PRIMARY KEY, + network TEXT, + episodes INTEGER, + FOREIGN KEY (show_id) REFERENCES media (id) + ); + ''') + conn.commit() + conn.close() + +def add_book(title , year, author, page): + conn = sqlite3.connect('my_library.db') + cursor = conn.cursor() + + cursor.execute("INSERT INTO media (title, type, release_year) VALUES (?, 'Book', ?)", (title, year)) + last_id = cursor.lastrowid + cursor.execute("INSERT INTO books (book_id, author, pages) VALUES (?, ?, ?)", (last_id, author, pages)) + + conn.commit() + conn.close() + print(f"Added {title} successfully!") + +def add_shows(title , year, network, episodes): + conn = sqlite3.connect('my_library') + cursor = conn.cursor() + + cursor.execute("INSERT INTO media(title, type, release_year) VALUES (?, 'Show',?)" , (title, year)) + last_id = cursor.lastrowid + cursor.execute("INSERT INTO shows(show_id , network , episodes) VALUES (?,?,?)" , (last_id,network,episodes)) + conn.commit() + conn.close() + print(f"Added {title} successfully!") + +#fetch +def get_all_media(): + conn = sqlite3.connect('my_library.db') + # This line makes results behave like dictionaries (e.g., row['title']) + conn.row_factory = sqlite3.Row + cursor = conn.cursor() + + query = """ + SELECT m.title, m.type, b.author, s.network + FROM media m + LEFT JOIN books b ON m.id = b.book_id + LEFT JOIN shows s ON m.id = s.show_id + """ + + rows = cursor.execute(query).fetchall() + conn.close() + return rows + +# Print the results +for item in get_all_media(): + print(f"{item['title']} ({item['type']})") + diff --git a/main.html b/main.html index cf47d09..fd44190 100644 --- a/main.html +++ b/main.html @@ -1,13 +1,13 @@ - + - Show log +
@@ -16,12 +16,25 @@

Book and Movie log

-
@@ -67,8 +80,7 @@
- - - + + diff --git a/template/card.html b/template/card.html new file mode 100644 index 0000000..e69de29