SexBot / utils /db_csv.py
Pew404's picture
Upload folder using huggingface_hub
318db6e verified
raw
history blame contribute delete
641 Bytes
from sqlalchemy import create_engine
from llama_index.core import SQLDatabase
import pandas as pd
db_user = "shenzhen_ai_for_vibemate_eson"
db_password = "dBsnc7OrM0MVi0FEhiHe2y"
db_host = "192.168.1.99"
db_port = 3306
db_name = "hytto_surfease"
engine = create_engine(f"mysql+pymysql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}")
sql_db = SQLDatabase(engine)
tables = sql_db.get_usable_table_names()
csv_dir = "/home/purui/projects/chatbot/data/csv"
for table in tables:
query = f"SELECT * FROM {table}"
df = pd.read_sql_query(query, engine)
csv_path = csv_dir+f"/{table}.csv"
df.to_csv(csv_path, index=False)