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