SHARE
TWEET

Untitled

a guest Jun 19th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import snowflake connector module
  2. import snowflake.connector
  3. from snowflake.connector.converter_null import SnowflakeNoConverterToPython
  4. from snowflake.connector import DictCursor
  5. import sys
  6. import os
  7. from cryptography.hazmat.backends import default_backend
  8. from cryptography.hazmat.primitives.asymmetric import rsa
  9. from cryptography.hazmat.primitives.asymmetric import dsa
  10. from cryptography.hazmat.primitives import serialization
  11.  
  12. # 確定輸入的參數是否給定正確
  13. # Sample: python Improving_Performance_Bypasstype.py <account> <user> <role>
  14. if len(sys.argv) < 4 :
  15.     print("ERROR: Please pass the following command-line parameters in order:",end='\n')
  16.     print("account,user,role.")
  17.     sys.exit(-1)
  18. else:
  19.     ACCOUNT = sys.argv[1]
  20.     USER = sys.argv[2]
  21.     ROLE = sys.argv[3]
  22.  
  23. with open("/Users/abehsu/Documents/Snowflake/Snowpipe_poc/rsa_key.p8", "rb") as key:
  24.     p_key = serialization.load_pem_private_key(
  25.         key.read(),
  26.         password = os.environ['PRIVATE_KEY_PASSPHRASE'].encode(),
  27.         backend=default_backend()
  28.     )
  29.  
  30. pkb = p_key.private_bytes(
  31.     encoding=serialization.Encoding.DER,
  32.     format=serialization.PrivateFormat.PKCS8,
  33.     encryption_algorithm=serialization.NoEncryption()
  34. )
  35.  
  36.  
  37. con = snowflake.connector.connect(
  38.     account=ACCOUNT,    
  39.     user=USER,
  40.     role=ROLE,
  41.     private_key=pkb,
  42.     converter_class=SnowflakeNoConverterToPython
  43. )
  44.  
  45. con.cursor().execute("USE WAREHOUSE SF_TUTS_WH")
  46. con.cursor().execute("USE SCHEMA DEMO_DB.PUBLIC")
  47.  
  48. for rec in con.cursor(DictCursor).execute("SELECT * FROM LIBRARY LIMIT 100"):
  49.     print(rec["BIBNUM"],rec["TITLE"],rec["AUTHOR"],rec["ISBN"],rec["PUBLICATIONYEAR"],rec["PUBLISHER"],rec["SUBJECTS"],rec["ITEMTYPE"],rec["ITEMCOLLECTION"],rec["FLOATINGITEM"],rec["ITEMLOCATION"],rec["REPORTDATE"],rec["ITEMCOUNT"])
  50.     print(type(rec["BIBNUM"]))
  51.     print(type(rec["REPORTDATE"]))
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