SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import os
  3.  
  4. from sqlalchemy import create_engine
  5.  
  6. user = os.environ["LOGNAME"]
  7.  
  8. def engcreate():
  9.     global rdsEngine
  10.    
  11.     with open("/home/" + user + "/Credentials/Redshift_user", "r") as rds_user:
  12.         rds_user = rds_user.read()
  13.        
  14.     with open("/home/" + user + "/Credentials/Redshift_pw", "r") as rds_pass:
  15.         rds_pass = rds_pass.read()
  16.        
  17.     rds_url   = "prd-XX-redshift-rds.XXX1XXXXXXXX.us-east-1.redshift.amazonaws.com"
  18.     rds_port  = "5439"
  19.     rds_dbase = "databasename"
  20.     rdsEngine = create_engine("postgresql://" + rds_user + ":" + rds_pass + "@" + rds_url + ":" + rds_port + "/" + rds_dbase)
  21.     return
  22.  
  23. engcreate()
  24.  
  25. rdsQuery = """
  26. SELECT *
  27. FROM thetable
  28. """
  29.  
  30. df = pd.read_sql_query(rdsQuery, rdsEngine)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top