import threading
import time
import os
import sqlite3
import inspect
from comicapi import comicarchive
from comicapi.issuestring import IssueString
from urllib import parse
from io import BytesIO
from PIL import Image
import datetime, pytz
from werkzeug.security import generate_password_hash
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String, BLOB, Boolean
from sqlalchemy.orm import sessionmaker

from scripts import database

db = sqlite3.connect(database.DATABASE)
db.row_factory = sqlite3.Row

engine = create_engine("sqlite:///"+database.DATABASE+"?check_same_thread=False")
Session =sessionmaker(bind=engine)
session = Session()
Base = declarative_base()


DC_Comics = ["DC", "Young Animal", "WildStorm", "Earth-M", "Vertigo", "Sandman Universe", "DC Black Label", "Wonder Comics", "DC Ink", "DC Zoom", "Mad", "All Star", "Amalgam Comics", "DC Focus", "Elseworlds", "First Wave", "Helix", "Impact Comics", "Johnny DC", "Minx", "Paradox Press", "Piranha Press", "Tangent Comics", "WildStorm Productions", "America's Best Comics", "Cliffhanger", "CMX Manga", "Homage Comics", "WildStorm Signature", "Zuda Comics"]

Marvel = ["Aircel Comics", "alibu Comics‎", "Atlas Comics", "Atlas", "CrossGen comics‎", "CrossGen", "Curtis Magazines", "Disney Books Group", "Disney Kingdoms", "Epic Comics", "Eternity Comics", "Humorama", "Icon Comics", "Infinite Comics", "Malibu Comics", "Marvel 2099", "Marvel Absurd", "Marvel Adventures", "Marvel Age", "Marvel Books", "Marvel Comics 2", "Marvel Comics", "Marvel Edge", "Marvel Frontier", "Marvel Illustrated", "Marvel Knights", "Marvel Magazine Group", "Marvel Mangaverse", "Marvel Monsters Group", "Marvel Music", "Marvel Next", "Marvel Noir", "Marvel Press", "Marvel UK", "Marvel Unlimited", "Max", "MAX", "MC2", "New Universe", "Paramount Comics", "Power Comics", "Razorline", "Star Comics", "Timely Comics", "Timely", "Tsunami", "Ultimate Comics", "Ultimate Marvel", "Non-Pareil Publishing Corp.", "St. Johns Publishing Co.", "Vital Publications, Inc."]


def get_db():
	return db
