use sqlite in memory
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import subprocess
|
||||
import sqlite3
|
||||
|
||||
conn = sqlite3.connect("Hentai.sqlite3")
|
||||
# conn = sqlite3.connect("Hentai.sqlite3")
|
||||
conn = sqlite3.connect(":memory:")
|
||||
conn.executescript("""
|
||||
DROP TABLE IF EXISTS artist;
|
||||
DROP TABLE IF EXISTS website;
|
||||
@ -32,10 +33,13 @@ conn.executescript("""
|
||||
def insert_into_db(website_name, url, artist):
|
||||
conn.execute(f"INSERT INTO website(name) VALUES('{website_name}')")
|
||||
conn.execute(f"INSERT INTO artist(name) VALUES('{artist}')")
|
||||
|
||||
sql = f"SELECT id FROM artist WHERE name like '{artist}'"
|
||||
artist_id = conn.execute(sql).fetchone()[0]
|
||||
|
||||
sql = f"SELECT id FROM website WHERE name like '{website_name}'"
|
||||
website_id = conn.execute(sql).fetchone()[0]
|
||||
|
||||
values = f"'{url}', '{website_id}', '{artist_id}'"
|
||||
sql = f"INSERT INTO links(url, website_id, artist_id) VALUES({values})"
|
||||
conn.execute(sql)
|
||||
@ -45,6 +49,8 @@ def import_website(website_name):
|
||||
file_name = f"downloaded_{website_name.lower()}.txt"
|
||||
file_contents = open(file_name).readlines()
|
||||
for line in file_contents:
|
||||
if line.startswith("#"):
|
||||
continue
|
||||
url = line.split("# ")[0].rstrip()
|
||||
artist = line.split("# ")[1].rstrip("\n")
|
||||
insert_into_db(website_name, url, artist)
|
||||
@ -74,8 +80,8 @@ def galleryDl(url, website_name, artist_name):
|
||||
|
||||
# This will not work with Rule34 as is
|
||||
# Rule34 will need it's artists to be added like the others
|
||||
import_website("Kemono")
|
||||
conn.commit()
|
||||
import_website("Coomer")
|
||||
# conn.commit()
|
||||
db_contents = read_db()
|
||||
conn.close()
|
||||
|
||||
|
Reference in New Issue
Block a user