Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import pymssql
  2. import pandas as pd
  3.  
  4. # db configurations DEFAULT
  5. sql_db_default = {
  6. "host_name": "192.168.1.100",
  7. "port": "1604",
  8. "user_name": "Base_User",
  9. "password": "HappyForYoU",
  10. "database_name": "BaseDB",
  11. "timeout": 300,
  12. "login_timeout": 300
  13. }
  14.  
  15. sql_query = 'use [BaseDB]; select * from tbl_name where name in (%s) ... Somme query (%s)'
  16.  
  17.  
  18. class MsSqlDataPuller(object):
  19. def __init__(self, **db_credentials):
  20. if not db_credentials:
  21. db_credentials = sql_db_default
  22. self.db_cred = db_credentials
  23. self.connection = pymssql.connect(
  24. host=self.db_cred["host_name"],
  25. port=self.db_cred["port"],
  26. user=self.db_cred["user_name"],
  27. password=self.db_cred["password"],
  28. database=self.db_cred["database_name"],
  29. login_timeout=self.db_cred["login_timeout"],
  30. timeout=self.db_cred["timeout"]
  31. )
  32.  
  33. def process(self, email_lists):
  34. # Execute the query and returns as panda data frame
  35. df = pd.read_sql_query(sql_query.format(email_lists, email_lists), self.connection)
  36. return df
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement