-
Notifications
You must be signed in to change notification settings - Fork 0
/
extraction.py
43 lines (29 loc) · 929 Bytes
/
extraction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from mysql.connector import connect, Error
import pandas as pd
import json
import os
try:
if not os.path.exists("tables"):
os.mkdir("tables")
with open("config3.json","r") as f:
config=json.load(f)
db_details=config["src_db"]
with connect(
host=db_details["host"],
user=db_details["user"],
password=db_details["password"],
database=db_details["database"]
) as connection:
cursor=connection.cursor()
tables='show tables'
cursor.execute(tables)
result=cursor.fetchall()
for i in result:
table=i[0]
content=f'select * from {table}'
df=pd.read_sql(content,connection)
df.to_csv(f"tables/{table}.csv",index=False)
except Error as e:
print(e)
finally:
print("Extraction Complete!!!")