Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymssql
- import pandas as pd
- # db configurations DEFAULT
- sql_db_default = {
- "host_name": "192.168.1.100",
- "port": "1604",
- "user_name": "Base_User",
- "password": "HappyForYoU",
- "database_name": "BaseDB",
- "timeout": 300,
- "login_timeout": 300
- }
- sql_query = 'use [BaseDB]; select * from tbl_name where name in (%s) ... Somme query (%s)'
- class MsSqlDataPuller(object):
- def __init__(self, **db_credentials):
- if not db_credentials:
- db_credentials = sql_db_default
- self.db_cred = db_credentials
- self.connection = pymssql.connect(
- host=self.db_cred["host_name"],
- port=self.db_cred["port"],
- user=self.db_cred["user_name"],
- password=self.db_cred["password"],
- database=self.db_cred["database_name"],
- login_timeout=self.db_cred["login_timeout"],
- timeout=self.db_cred["timeout"]
- )
- def process(self, email_lists):
- # Execute the query and returns as panda data frame
- df = pd.read_sql_query(sql_query.format(email_lists, email_lists), self.connection)
- return df
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement