berryworld 1.0.0.179222__py3-none-any.whl → 1.0.0.180127__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- berryworld/credentials.py +20 -0
- berryworld/snowflake_conn.py +77 -0
- {berryworld-1.0.0.179222.dist-info → berryworld-1.0.0.180127.dist-info}/METADATA +1 -1
- {berryworld-1.0.0.179222.dist-info → berryworld-1.0.0.180127.dist-info}/RECORD +7 -6
- {berryworld-1.0.0.179222.dist-info → berryworld-1.0.0.180127.dist-info}/WHEEL +1 -1
- {berryworld-1.0.0.179222.dist-info → berryworld-1.0.0.180127.dist-info}/LICENSE +0 -0
- {berryworld-1.0.0.179222.dist-info → berryworld-1.0.0.180127.dist-info}/top_level.txt +0 -0
berryworld/credentials.py
CHANGED
|
@@ -253,3 +253,23 @@ class MicrosoftTeamsCredentials:
|
|
|
253
253
|
|
|
254
254
|
except ValueError as e:
|
|
255
255
|
raise ValueError("Variable %s not found" % str(e))
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class SnowflakeCredentials:
|
|
259
|
+
def __init__(self, db_name):
|
|
260
|
+
if db_name is None:
|
|
261
|
+
raise ValueError("Please provide a value for db_name")
|
|
262
|
+
self.db_name = db_name
|
|
263
|
+
|
|
264
|
+
def simple_creds(self):
|
|
265
|
+
try:
|
|
266
|
+
account = os.environ.get("SNOWFLAKE_" + self.db_name.upper() + '_ACCOUNT')
|
|
267
|
+
user_name = os.environ.get("SNOWFLAKE_" + self.db_name.upper() + '_USERNAME')
|
|
268
|
+
password = os.environ.get("SNOWFLAKE_" + self.db_name.upper() + '_PASSWORD')
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
'account': account,
|
|
272
|
+
'user_name': user_name,
|
|
273
|
+
'password': password}
|
|
274
|
+
except ValueError as e:
|
|
275
|
+
raise ValueError("Variable %s not found" % str(e))
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import snowflake.connector
|
|
3
|
+
from credentials import SnowflakeCredentials
|
|
4
|
+
|
|
5
|
+
pd.set_option('future.no_silent_downcasting', True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SnowflakeConn:
|
|
9
|
+
def __init__(self, server_creds=None, **kwargs):
|
|
10
|
+
""" Initialize the class
|
|
11
|
+
-----------------------------
|
|
12
|
+
server_creds = {
|
|
13
|
+
"account": "",
|
|
14
|
+
"db_name": "",
|
|
15
|
+
"user_name": "",
|
|
16
|
+
"password": ""
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
-----------------------------
|
|
20
|
+
:param server_creds: Dictionary containing the info to connect to the Server
|
|
21
|
+
:param kwargs: Additional parameters to be passed to the connection
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
self.conn_str = None
|
|
25
|
+
self.conn = None
|
|
26
|
+
|
|
27
|
+
if kwargs != {}:
|
|
28
|
+
try:
|
|
29
|
+
db = kwargs['db_name']
|
|
30
|
+
server_creds = SnowflakeCredentials(db).simple_creds()
|
|
31
|
+
except KeyError:
|
|
32
|
+
raise KeyError('Please provide a valid db_name and server_type')
|
|
33
|
+
|
|
34
|
+
self.db = kwargs['db_name']
|
|
35
|
+
self.user = server_creds['user_name']
|
|
36
|
+
self.pw = server_creds['password']
|
|
37
|
+
self.account = server_creds['account']
|
|
38
|
+
|
|
39
|
+
if self.user and self.pw and self.account:
|
|
40
|
+
self.connect()
|
|
41
|
+
|
|
42
|
+
def connect(self):
|
|
43
|
+
""" Open the connection to Snowflake """
|
|
44
|
+
self.conn = snowflake.connector.connect(
|
|
45
|
+
user=self.user,
|
|
46
|
+
password=self.pw,
|
|
47
|
+
account=self.account,
|
|
48
|
+
database=self.db)
|
|
49
|
+
|
|
50
|
+
def close(self):
|
|
51
|
+
""" Close the connection to Snowflake """
|
|
52
|
+
self.conn.close()
|
|
53
|
+
|
|
54
|
+
def query(self, sql_query):
|
|
55
|
+
""" Read data from Snowflake according to the sql_query
|
|
56
|
+
-----------------------------
|
|
57
|
+
query_str = "SELECT * FROM %s" & table
|
|
58
|
+
con_.query(query_str)
|
|
59
|
+
-----------------------------
|
|
60
|
+
:param sql_query: Query to be sent to Snowflake
|
|
61
|
+
:return: DataFrame gathering the requested data
|
|
62
|
+
"""
|
|
63
|
+
cursor = None
|
|
64
|
+
self.connect()
|
|
65
|
+
try:
|
|
66
|
+
cursor = self.conn.cursor()
|
|
67
|
+
cursor.execute(sql_query)
|
|
68
|
+
rows = cursor.fetchall()
|
|
69
|
+
col_names = [desc[0] for desc in cursor.description]
|
|
70
|
+
result = pd.DataFrame(rows, columns=col_names)
|
|
71
|
+
return result
|
|
72
|
+
except Exception as e:
|
|
73
|
+
raise Exception(e)
|
|
74
|
+
finally:
|
|
75
|
+
if cursor:
|
|
76
|
+
cursor.close()
|
|
77
|
+
self.close()
|
|
@@ -4,7 +4,7 @@ berryworld/allocation_solver.py,sha256=asFtaCAze6-eHUGWXA0kAp67UBS-Upj1KKdrVLj_t
|
|
|
4
4
|
berryworld/app_logs.py,sha256=MKzKPYd3JuPfOQNAapIgaeZeFHw1z_w2mbn9I6QCADE,4180
|
|
5
5
|
berryworld/app_logs_query.py,sha256=U94b-z3X9cuY_KFozupUcfaYciXWBn7p_RHkoRsfROU,4376
|
|
6
6
|
berryworld/cache_data.py,sha256=AWAhV4PPkilZ4Xb1pUXuuu6UdHICAx8QqDtb9rVnjDM,2254
|
|
7
|
-
berryworld/credentials.py,sha256=
|
|
7
|
+
berryworld/credentials.py,sha256=L70ZzSNaS2mbHtSS8lb3iesd1XSwZNnUzGznlEKxlJY,11018
|
|
8
8
|
berryworld/devops.py,sha256=BAsVonVwCXoApUOovkt-BCzwc6KnXjxRDGff_ejSGw8,9719
|
|
9
9
|
berryworld/email_con.py,sha256=uSBzs_Ijz9pUPWt9e7U3TCB7i6q7hU1bB5vhsTB_tmw,14448
|
|
10
10
|
berryworld/email_logging.py,sha256=LeSrTExhQhar49gJR2wGC1dS0lqsNpFl9pS3eYWqnuo,4936
|
|
@@ -17,6 +17,7 @@ berryworld/pickle_management.py,sha256=O49ojVtTqYCT510rVRTbZWWaur_-5q3HSVG03Azn8
|
|
|
17
17
|
berryworld/postgres_connection.py,sha256=whKDnchd5Feqpmxpoh2vlyn36EKHR-dVEULYq0N_4wA,8287
|
|
18
18
|
berryworld/power_automate.py,sha256=9rDuRy0v-Ttq-SThid4lOB_tD4ibkyEmobiROpa--g4,25414
|
|
19
19
|
berryworld/sharepoint_con.py,sha256=TuH-Vxk1VxjTi7x80KFssf_J8YPLRXpV27RBaFZi37U,22254
|
|
20
|
+
berryworld/snowflake_conn.py,sha256=qd7kjeGDBUtMQqSfR0rCVz1Qn6d9U3zskBvfLRNSofc,2480
|
|
20
21
|
berryworld/sql_conn.py,sha256=meDAf_92hNW5Zp5sv_PPeIUA8NDchaDtVN7zo77veIA,47491
|
|
21
22
|
berryworld/teams_logging.py,sha256=8NwXyWr4fLj7W6GzAm2nRQCGFDxibQpAHDHHD24FrP8,6997
|
|
22
23
|
berryworld/transportation_solver.py,sha256=gdlHRgl2wlp5EV0uhKIOYtkkbAlHaFHGktnMgvuENWE,5022
|
|
@@ -28,8 +29,8 @@ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
28
29
|
tests/test_allocation_config.py,sha256=e12l6fE9U57eSPS35g6ekJ_hol7-RHg89JV60_m1BlE,4633
|
|
29
30
|
tests/test_handy_mix_config.py,sha256=Un56mz9KJmdn4K4OwzHAHLSRzDU1Xv2nFrONNuzOG04,2594
|
|
30
31
|
tests/test_xml_parser.py,sha256=3QTlhFEd6KbK6nRFKZnc35tad6wqukTbe4QrFi8mr_8,859
|
|
31
|
-
berryworld-1.0.0.
|
|
32
|
-
berryworld-1.0.0.
|
|
33
|
-
berryworld-1.0.0.
|
|
34
|
-
berryworld-1.0.0.
|
|
35
|
-
berryworld-1.0.0.
|
|
32
|
+
berryworld-1.0.0.180127.dist-info/LICENSE,sha256=vtkVCJM6E2af2gnsi2XxKPr4WY-uIbvzVLXieFND0UU,1074
|
|
33
|
+
berryworld-1.0.0.180127.dist-info/METADATA,sha256=k_9Yaln2DC97Fes4tsW8U2GPrfZ9t2pzXDHOOCPhCcA,1091
|
|
34
|
+
berryworld-1.0.0.180127.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
35
|
+
berryworld-1.0.0.180127.dist-info/top_level.txt,sha256=GIZ5qy-P5oxfEH755vA1IMFeTVdX3-40JxMe6nOe5I8,17
|
|
36
|
+
berryworld-1.0.0.180127.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|