diff --git a/BookandMovieDB.py b/BookandMovieDB.py new file mode 100644 index 0000000..4ecbee7 --- /dev/null +++ b/BookandMovieDB.py @@ -0,0 +1,72 @@ +import sqlite3, os +from flask import Flask, render_template, request, redirect, url_for + +app = Flask(__name__) +DB_NAME = './db/my_library.db' +UPLOAD_FOLDER = 'static/covers' +os.makedirs(UPLOAD_FOLDER, exist_ok=True) + +def init_db(): + conn = sqlite3.connect(DB_NAME) + cursor = conn.cursor() + cursor.executescript(''' + CREATE TABLE IF NOT EXISTS media ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + title TEXT NOT NULL, type TEXT, release_year INTEGER, image_path TEXT DEFAULT 'default.jpg' + ); + CREATE TABLE IF NOT EXISTS books (book_id INTEGER PRIMARY KEY, author TEXT, FOREIGN KEY (book_id) REFERENCES media (id)); + CREATE TABLE IF NOT EXISTS shows (show_id INTEGER PRIMARY KEY, network TEXT, FOREIGN KEY (show_id) REFERENCES media (id)); + CREATE TABLE IF NOT EXISTS genres (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE); + CREATE TABLE IF NOT EXISTS media_genres (media_id INTEGER, genre_id INTEGER); + ''') + genres = [('Sci-Fi',), ('Fantasy',), ('Horror',), ('Drama',), ('Comedy',)] + cursor.executemany("INSERT OR IGNORE INTO genres (name) VALUES (?)", genres) + conn.commit() + conn.close() + +@app.route('/') +def index(): + conn = sqlite3.connect(DB_NAME) + conn.row_factory = sqlite3.Row + query = """ + SELECT m.*, b.author, s.network, GROUP_CONCAT(g.name, ', ') as genre_list + FROM media m + LEFT JOIN books b ON m.id = b.book_id + LEFT JOIN shows s ON m.id = s.show_id + LEFT JOIN media_genres mg ON m.id = mg.media_id + LEFT JOIN genres g ON mg.genre_id = g.id + GROUP BY m.id + """ + items = conn.execute(query).fetchall() + all_genres = conn.execute("SELECT * FROM genres").fetchall() + conn.close() + return render_template('main.html', items=items, genres=all_genres) + +@app.route('/add', methods=['POST']) +def add_media(): + title, m_type, year = request.form['title'], request.form['type'], request.form['year'] + extra, genre_id = request.form['extra_info'], request.form['genre_id'] + + file = request.files.get('cover_image') + filename = file.filename if file and file.filename != '' else 'default.jpg' + if file and file.filename != '': + file.save(os.path.join(UPLOAD_FOLDER, filename)) + + conn = sqlite3.connect(DB_NAME) + cursor = conn.cursor() + cursor.execute("INSERT INTO media (title, type, release_year, image_path) VALUES (?, ?, ?, ?)", (title, m_type, year, filename)) + m_id = cursor.lastrowid + cursor.execute("INSERT INTO media_genres (media_id, genre_id) VALUES (?, ?)", (m_id, genre_id)) + + if m_type == 'Book': + cursor.execute("INSERT INTO books (book_id, author) VALUES (?, ?)", (m_id, extra)) + else: + cursor.execute("INSERT INTO shows (show_id, network) VALUES (?, ?)", (m_id, extra)) + + conn.commit() + conn.close() + return redirect(url_for('index')) + +if __name__ == '__main__': + init_db() + app.run(debug=True) diff --git a/__pycache__/BookandMovieDB.cpython-313.pyc b/__pycache__/BookandMovieDB.cpython-313.pyc new file mode 100644 index 0000000..9f177fe Binary files /dev/null and b/__pycache__/BookandMovieDB.cpython-313.pyc differ diff --git a/db/BookandMovieDB.py b/db/BookandMovieDB.py deleted file mode 100644 index a00d03d..0000000 --- a/db/BookandMovieDB.py +++ /dev/null @@ -1,76 +0,0 @@ -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/db/my_library.db b/db/my_library.db new file mode 100644 index 0000000..9763ca3 Binary files /dev/null and b/db/my_library.db differ diff --git a/static/covers/Shadows_House_01.png b/static/covers/Shadows_House_01.png new file mode 100644 index 0000000..a5eb619 Binary files /dev/null and b/static/covers/Shadows_House_01.png differ diff --git a/static/css/card.css b/static/css/card.css new file mode 100644 index 0000000..a960d0b --- /dev/null +++ b/static/css/card.css @@ -0,0 +1,45 @@ +.grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); + gap: 25px; +} + +.card { + background: white; + border-radius: 15px; + overflow: hidden; + box-shadow: 0 10px 20px rgba(0,0,0,0.05); +} + +.card img { + width: 100%; + height: 320px; + object-fit: cover; +} + +.content { + padding: 15px; +} + +.badge { + padding: 4px 10px; + border-radius: 20px; + color: white; + font-size: 0.7rem; + font-weight: bold; +} + +.book-badge { + background: var(--book-color); +} + +.show-badge { + background: var(--show-color); +} + +.genre-list { + display: block; + color: #888; + font-size: 0.8rem; + margin: 5px 0; +} diff --git a/static/css/style.css b/static/css/style.css new file mode 100644 index 0000000..612c423 --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,61 @@ +:root { + --ink: #1a1409; + --cream: #f5f0e8; + --parchment: #ede8dc; + --amber: #c8822a; + --amber-light: #e8a84a; + --sage: #7a8c6e; + --rust: #a84832; + --muted: #7a7060; + --card-bg: #faf7f2; + } + +#body_page{ + display: flex; + flex-direction: row; + background-color:var(--cream); +} +#side_bar{ + background-color:var(--ink); + display:flex; + flex-direction: column; + justify-content:center; + height: 100vh; + width: 30vw; +} +#menu{ + list-style-type:none; + padding: 0; + +} +#menu-button{ + text-decoration:none; +} + +#home_nav{ + display:flex; + flex-direction:row; + justify-content:space-around; + align-content:center; + width:80vw; + padding:20px; +} +#addLog_button{ + display:flex; + align-items:center; + gap:8px; + background-color:var(--amber); + color:white; + border:none; + border-radius:40px; + padding:12px 22px; + font-size: 13px; + font-weight: 500; + cursor: pointer; + box-shadow: 0 4px 14px rgba(200,130,42,0.35); + transition: all 0.2s; +} + +#navagtor{ + +} diff --git a/static/js/main.js b/static/js/main.js new file mode 100644 index 0000000..e69de29 diff --git a/templates/card.html b/templates/card.html new file mode 100644 index 0000000..b41cf7f --- /dev/null +++ b/templates/card.html @@ -0,0 +1,16 @@ +
+ Cover +
+ + {{ item.type }} + +

{{ item.title }}

+ 🏷️ {{ item.genre_list }} + +

{{ item.author if item.type == 'Book' else item.network }}

+ +
+ Released: {{ item.release_year }} +
+
+
diff --git a/templates/main.html b/templates/main.html new file mode 100644 index 0000000..2cf95f0 --- /dev/null +++ b/templates/main.html @@ -0,0 +1,114 @@ + + + + + + + + + Show log + + + + + + + + + + + +
+ + + +
+
+ +

+ Good evening +

+
+ +
+
+ + log a book/show +
+
+ + +
+
+ + + + +
+
+

+ My log +

+ +
+ +
+ +
+ + +
+
+

📚 My Library

+
+ + + + + + + +
+
+
+ {% for item in items %} + {% include 'card.html' %} + {% endfor %} +
+
+ + +
+
+
+
+
+ + + +