Jannchie's picture
feat(scripts): add fetch scripts
f66a537
import sqlite3
from sqlalchemy import Column, Float, Index, Integer, MetaData, Table, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
Base = declarative_base()
metadata = MetaData()
t_posts = Table(
"posts",
metadata,
Column("id", Integer, primary_key=True),
Column("filename", Text),
Column("mimetype", Text),
Column("extension", Text),
Column("width", Integer),
Column("height", Integer),
Column("rating", Text),
Column("file_url", Text),
Column("created_at", Text),
Column("uploader_id", Integer),
Column("score", Integer),
Column("source", Text),
Column("md5", Text),
Column("last_comment_bumped_at", Text),
Column("image_width", Integer),
Column("image_height", Integer),
Column("tag_string", Text),
Column("fav_count", Integer),
Column("file_ext", Text),
Column("last_noted_at", Text),
Column("parent_id", Float),
Column("has_children", Integer),
Column("approver_id", Float),
Column("tag_count_general", Integer),
Column("tag_count_artist", Integer),
Column("tag_count_character", Integer),
Column("tag_count_copyright", Integer),
Column("file_size", Integer),
Column("up_score", Integer),
Column("down_score", Integer),
Column("is_pending", Integer),
Column("is_flagged", Integer),
Column("is_deleted", Integer),
Column("tag_count", Integer),
Column("updated_at", Text),
Column("is_banned", Integer),
Column("pixiv_id", Float),
Column("last_commented_at", Text),
Column("has_active_children", Integer),
Column("bit_flags", Integer),
Column("tag_count_meta", Integer),
Column("has_large", Integer),
Column("has_visible_children", Integer),
Column("tag_string_general", Text),
Column("tag_string_character", Text),
Column("tag_string_copyright", Text),
Column("tag_string_artist", Text),
Column("tag_string_meta", Text),
Column("large_file_url", Text),
Column("preview_file_url", Text),
Index("posts_index_file_url", "file_url"),
Index("posts_index_tag_count_artist", "tag_count_artist"),
Index("posts_index_tag_count_character", "tag_count_character"),
Index("posts_index_tag_count_copyright", "tag_count_copyright"),
Index("posts_index_tag_count_general", "tag_count_general"),
Index("posts_index_tag_count_meta", "tag_count_meta"),
Index("posts_index_tag_string", "tag_string"),
Index("posts_index_tag_string_artist", "tag_string_artist"),
Index("posts_index_tag_string_character", "tag_string_character"),
Index("posts_index_tag_string_copyright", "tag_string_copyright"),
Index("posts_index_tag_string_general", "tag_string_general"),
Index("posts_index_tag_string_meta", "tag_string_meta"),
Index("posts_index_rating", "rating"),
Index("posts_index_score", "score"),
)
def connect_db(db_name):
return sqlite3.connect(db_name)
def get_engine(db_name):
return create_engine(f"sqlite:///{db_name}")
def get_session(engine):
Session = sessionmaker(bind=engine)
return Session()
if __name__ == "__main__":
print("Database has been created.")