From 48ac70c56ea1ba076221892bad984d5d491a8673 Mon Sep 17 00:00:00 2001 From: Snupai Date: Mon, 1 Apr 2024 17:50:04 +0200 Subject: [PATCH] Add glyph_db module to subclasses package --- subclasses/__init__.py | 2 +- subclasses/glyph_db.py | 89 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/subclasses/__init__.py b/subclasses/__init__.py index cd53607..9f58ec8 100644 --- a/subclasses/__init__.py +++ b/subclasses/__init__.py @@ -1,3 +1,3 @@ from .filebin import * from .glyph_tools import * - +from .glyph_db import * diff --git a/subclasses/glyph_db.py b/subclasses/glyph_db.py index 08e9023..a1692fc 100644 --- a/subclasses/glyph_db.py +++ b/subclasses/glyph_db.py @@ -2,5 +2,92 @@ print("This is a subclass. Please use the main bot.py file.") exit() +import sqlite3 +import os + #TODO:implement database shit - \ No newline at end of file + +def insert_data(Title, Youtube_Link, Timestamp, Phone, Creator, Compressed_Glyphdata): + # Connect to the database + conn = sqlite3.connect('Custom_Glyphs.db') + cursor = conn.cursor() + + # Prepare the SQL statement + insert_sql = ''' + INSERT INTO Custom_Glyphs (Title, Youtube_Link, Timestamp, Phone, Creator, Compressed_Glyphdata) + VALUES (?, ?, ?, ?, ?, ?) + ''' + + # Execute the SQL statement with the values + cursor.execute(insert_sql, (Title, Youtube_Link, Timestamp, Phone, Creator, Compressed_Glyphdata)) + + # Commit and close the connection + conn.commit() + conn.close() + + +def get_data_by_ID(entry_id): + # Connect to the database + conn = sqlite3.connect('Custom_Glyphs.db') + cursor = conn.cursor() + + # Prepare the SQL statement + select_sql = 'SELECT * FROM Custom_Glyphs WHERE id=?' + + # Execute the SQL statement with the values + cursor.execute(select_sql, (entry_id,)) + result = cursor.fetchone() + + # Extract the file + if result is not None: + file_data = result[6] + + # Create folder + folder_name = str(entry_id) + if not os.path.exists(folder_name): + os.makedirs(folder_name) + + # Save the file + file_name = os.path.join(folder_name, f'entry_{entry_id}.zip') + with open(file_name, 'wb') as file: + file.write(file_data) + + # Close the connection + conn.close() + + +def get_data_by_Title(Title): + # Connect to the database + conn = sqlite3.connect('Custom_Glyphs.db') + cursor = conn.cursor() + + # Prepare the SQL statement + select_sql = 'SELECT * FROM Custom_Glyphs WHERE Title=?' + + # Execute the SQL statement with the values + cursor.execute(select_sql, (Title,)) + result = cursor.fetchone() + + if result is not None: + print("ID:", result[0]) + print("Title:", result[1]) + print("Youtube_Link:", result[2]) + print("Timestamp:", result[3]) + print("Phone:", result[4]) + print("Creator:", result[5]) + + # Extract the file + file_data = result[6] + + # Create folder + folder_name = str(result[0]) + if not os.path.exists(folder_name): + os.makedirs(folder_name) + + # Save the file + file_name = os.path.join(folder_name, f'entry_{result[0]}.zip') + with open(file_name, 'wb') as file: + file.write(file_data) + + # Close the connection + conn.close() \ No newline at end of file