-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlwrite.py
More file actions
37 lines (32 loc) · 1.26 KB
/
Copy pathsqlwrite.py
File metadata and controls
37 lines (32 loc) · 1.26 KB
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
import pandas as pd
from sqlalchemy import create_engine, URL,exc
class sqlwrt():
def writedb(self, data):
connect_args = {
"ssl_verify_cert": True,
"ssl_verify_identity": True,
"ssl_ca": r"G:\DS\guvi\Projects\Project2\DDSA\DDSA_Code\certificate\isrgrootx1.pem",
}
engine = create_engine(
URL.create(
drivername="mysql+pymysql",
username="3LHApunfAprgwZ4.root",
password="UTR1eix9QCrXfwML",
host="gateway01.ap-southeast-1.prod.aws.tidbcloud.com",
port=4000,
database="nifty50",
), connect_args=connect_args)
try:
#columntype={"ratingsCount": Integer}
data.to_sql(
name="stocks", # Table name
con=engine, # SQLAlchemy engine
if_exists="append", # Options: 'fail', 'replace', 'append'
index=False, # Do not write the DataFrame index as a column
#dtype=columntype
)
except exc.SQLAlchemyError as e:
print(e)
finally:
engine.dispose()
return "Engine closed"