Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 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. # Put any query you want with format options or not
  16. sql_query = 'use [BaseDB]; select * from tbl_name where name in (%s) ... Somme query (%s)'
  17.  
  18.  
  19. class MsSqlDataPuller(object):
  20. def __init__(self, **db_credentials):
  21. if not db_credentials:
  22. db_credentials = sql_db_default
  23. self.db_cred = db_credentials
  24. self.connection = pymssql.connect(
  25. host=self.db_cred["host_name"],
  26. port=self.db_cred["port"],
  27. user=self.db_cred["user_name"],
  28. password=self.db_cred["password"],
  29. database=self.db_cred["database_name"],
  30. login_timeout=self.db_cred["login_timeout"],
  31. timeout=self.db_cred["timeout"]
  32. )
  33.  
  34. def process(self, email_lists):
  35. # Execute the query and returns as panda data frame
  36. df = pd.read_sql_query(sql_query.format(email_lists, email_lists), self.connection)
  37. return df
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement