wcp-library 1.1.8__tar.gz → 1.2.1__tar.gz

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.
Files changed (25) hide show
  1. {wcp_library-1.1.8 → wcp_library-1.2.1}/PKG-INFO +3 -1
  2. {wcp_library-1.1.8 → wcp_library-1.2.1}/pyproject.toml +3 -1
  3. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/async_sql/oracle.py +11 -7
  4. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/async_sql/postgres.py +11 -7
  5. wcp_library-1.2.1/wcp_library/selenium_helper.py +77 -0
  6. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/sql/oracle.py +11 -7
  7. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/sql/postgres.py +11 -7
  8. {wcp_library-1.1.8 → wcp_library-1.2.1}/README.md +0 -0
  9. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/__init__.py +0 -0
  10. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/async_credentials/__init__.py +0 -0
  11. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/async_credentials/api.py +0 -0
  12. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/async_credentials/oracle.py +0 -0
  13. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/async_credentials/postgres.py +0 -0
  14. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/async_sql/__init__.py +0 -0
  15. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/credentials/__init__.py +0 -0
  16. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/credentials/ftp.py +0 -0
  17. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/credentials/oracle.py +0 -0
  18. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/credentials/postgres.py +0 -0
  19. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/emailing.py +0 -0
  20. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/ftp/__init__.py +0 -0
  21. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/ftp/ftp.py +0 -0
  22. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/ftp/sftp.py +0 -0
  23. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/informatica.py +0 -0
  24. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/logging.py +0 -0
  25. {wcp_library-1.1.8 → wcp_library-1.2.1}/wcp_library/sql/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wcp-library
3
- Version: 1.1.8
3
+ Version: 1.2.1
4
4
  Summary: Common utilites for internal development at WCP
5
5
  Home-page: https://github.com/Whitecap-DNA/WCP-Library
6
6
  Author: Mitch-Petersen
@@ -20,6 +20,8 @@ Requires-Dist: psycopg-binary (>=3.2.3,<4.0.0)
20
20
  Requires-Dist: psycopg-pool (>=3.2.3,<4.0.0)
21
21
  Requires-Dist: pycryptodome (>=3.21.0,<4.0.0)
22
22
  Requires-Dist: requests (>=2.32.3,<3.0.0)
23
+ Requires-Dist: selenium (>=4.27.1,<5.0.0)
24
+ Requires-Dist: webdriver-manager (>=4.0.2,<5.0.0)
23
25
  Requires-Dist: yarl (>=1.17.1,<2.0.0)
24
26
  Project-URL: Documentation, https://github.com/Whitecap-DNA/WCP-Library/wiki
25
27
  Project-URL: Repository, https://github.com/Whitecap-DNA/WCP-Library
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "wcp-library"
3
- version = "1.1.8"
3
+ version = "1.2.1"
4
4
  description = "Common utilites for internal development at WCP"
5
5
  authors = ["Mitch-Petersen <mitch.petersen@wcap.ca>"]
6
6
  readme = "README.md"
@@ -21,6 +21,8 @@ psycopg-binary = "^3.2.3"
21
21
  psycopg-pool = "^3.2.3"
22
22
  pycryptodome = "^3.21.0"
23
23
  requests = "^2.32.3"
24
+ selenium = "^4.27.1"
25
+ webdriver-manager = "^4.0.2"
24
26
  yarl = "^1.17.1"
25
27
 
26
28
  [build-system]
@@ -1,6 +1,7 @@
1
1
  import logging
2
2
  from typing import Optional
3
3
 
4
+ import numpy as np
4
5
  import pandas as pd
5
6
  import oracledb
6
7
  from oracledb import AsyncConnectionPool
@@ -204,14 +205,17 @@ class AsyncOracleConnection(object):
204
205
  bindList.append(':' + column)
205
206
  bind = ', '.join(bindList)
206
207
 
207
- main_dict = dfObj.to_dict('records')
208
208
  if remove_nan:
209
- for val, item in enumerate(main_dict):
210
- for sub_item, value in item.items():
211
- if pd.isna(value):
212
- main_dict[val][sub_item] = None
213
- else:
214
- main_dict[val][sub_item] = value
209
+ dfObj = dfObj.replace({np.nan: None})
210
+ main_dict = dfObj.to_dict('records')
211
+
212
+ # if remove_nan:
213
+ # for val, item in enumerate(main_dict):
214
+ # for sub_item, value in item.items():
215
+ # if pd.isna(value):
216
+ # main_dict[val][sub_item] = None
217
+ # else:
218
+ # main_dict[val][sub_item] = value
215
219
 
216
220
  query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, bind)
217
221
  await self.execute_many(query, main_dict)
@@ -1,6 +1,7 @@
1
1
  import logging
2
2
  from typing import Optional
3
3
 
4
+ import numpy as np
4
5
  import pandas as pd
5
6
  from psycopg.sql import SQL
6
7
  from psycopg_pool import AsyncConnectionPool
@@ -187,14 +188,17 @@ class AsyncPostgresConnection(object):
187
188
  param_list.append(f"%({column})s")
188
189
  params = ', '.join(param_list)
189
190
 
190
- main_dict = dfObj.to_dict('records')
191
191
  if remove_nan:
192
- for val, item in enumerate(main_dict):
193
- for sub_item, value in item.items():
194
- if pd.isna(value):
195
- main_dict[val][sub_item] = None
196
- else:
197
- main_dict[val][sub_item] = value
192
+ dfObj = dfObj.replace({np.nan: None})
193
+ main_dict = dfObj.to_dict('records')
194
+
195
+ # if remove_nan:
196
+ # for val, item in enumerate(main_dict):
197
+ # for sub_item, value in item.items():
198
+ # if pd.isna(value):
199
+ # main_dict[val][sub_item] = None
200
+ # else:
201
+ # main_dict[val][sub_item] = value
198
202
 
199
203
  query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, params)
200
204
  await self.execute_many(query, main_dict)
@@ -0,0 +1,77 @@
1
+ from pathlib import Path
2
+ from typing import Optional
3
+
4
+ from selenium import webdriver
5
+ from selenium.webdriver.common.by import By
6
+ from selenium.webdriver.chrome.service import Service
7
+ from selenium.webdriver.support import expected_conditions
8
+ from selenium.webdriver.support.wait import WebDriverWait
9
+ from selenium.webdriver.remote.webelement import WebElement
10
+ from webdriver_manager.chrome import ChromeDriverManager
11
+
12
+
13
+ class SeleniumHelper:
14
+ def __init__(self, headless: bool = False, download_path: Optional[Path] = None):
15
+ self._headless = headless
16
+ self._download_path = download_path
17
+
18
+ opt = webdriver.ChromeOptions()
19
+ opt.add_argument("--start-maximized")
20
+ if headless:
21
+ opt.add_argument('headless')
22
+
23
+ opt.page_load_strategy = 'eager'
24
+
25
+ experimental_options_dict = {"download.prompt_for_download": False,
26
+ "download.directory_upgrade": True,
27
+ "safebrowsing.enabled": True}
28
+ if download_path:
29
+ experimental_options_dict["download.default_directory"] = str(download_path)
30
+
31
+ opt.add_experimental_option("prefs", experimental_options_dict)
32
+ opt.timeouts = {'implicit': 5000}
33
+
34
+ self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=opt)
35
+
36
+
37
+ def find_button_by_text(self, text: str) -> WebElement:
38
+ """
39
+ Find a button by its text
40
+
41
+ :param text:
42
+ :return button element:
43
+ """
44
+
45
+ buttons = self.driver.find_elements(By.TAG_NAME, 'Button')
46
+ for b in buttons:
47
+ if b.text == text:
48
+ return b
49
+
50
+ # If there is something weird with the button text, this should find it
51
+ for b in buttons:
52
+ if text in b.text:
53
+ return b
54
+
55
+ def find_span_by_text(self, text: str) -> WebElement:
56
+ """
57
+ Find a span by its text
58
+
59
+ :param text:
60
+ :return span element:
61
+ """
62
+
63
+ buttons = self.driver.find_elements(By.TAG_NAME, 'Span')
64
+ for b in buttons:
65
+ if b.text == text:
66
+ return b
67
+
68
+ def wait_until_element_visible(self, css_element: str, timeout: int = 30) -> None:
69
+ """
70
+ Wait until an element is visible
71
+
72
+ :param css_element:
73
+ :param timeout:
74
+ :return:
75
+ """
76
+
77
+ WebDriverWait(self.driver, timeout).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, css_element)))
@@ -1,6 +1,7 @@
1
1
  import logging
2
2
  from typing import Optional
3
3
 
4
+ import numpy as np
4
5
  import pandas as pd
5
6
  import oracledb
6
7
  from oracledb import ConnectionPool
@@ -208,14 +209,17 @@ class OracleConnection(object):
208
209
  bindList.append(':' + column)
209
210
  bind = ', '.join(bindList)
210
211
 
211
- main_dict = dfObj.to_dict('records')
212
212
  if remove_nan:
213
- for val, item in enumerate(main_dict):
214
- for sub_item, value in item.items():
215
- if pd.isna(value):
216
- main_dict[val][sub_item] = None
217
- else:
218
- main_dict[val][sub_item] = value
213
+ dfObj = dfObj.replace({np.nan: None})
214
+ main_dict = dfObj.to_dict('records')
215
+
216
+ # if remove_nan:
217
+ # for val, item in enumerate(main_dict):
218
+ # for sub_item, value in item.items():
219
+ # if pd.isna(value):
220
+ # main_dict[val][sub_item] = None
221
+ # else:
222
+ # main_dict[val][sub_item] = value
219
223
 
220
224
  query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, bind)
221
225
  self.execute_many(query, main_dict)
@@ -1,6 +1,7 @@
1
1
  import logging
2
2
  from typing import Optional
3
3
 
4
+ import numpy as np
4
5
  import pandas as pd
5
6
  from psycopg.sql import SQL
6
7
  from psycopg_pool import ConnectionPool
@@ -187,14 +188,17 @@ class PostgresConnection(object):
187
188
  param_list.append(f"%({column})s")
188
189
  params = ', '.join(param_list)
189
190
 
190
- main_dict = dfObj.to_dict('records')
191
191
  if remove_nan:
192
- for val, item in enumerate(main_dict):
193
- for sub_item, value in item.items():
194
- if pd.isna(value):
195
- main_dict[val][sub_item] = None
196
- else:
197
- main_dict[val][sub_item] = value
192
+ dfObj = dfObj.replace({np.nan: None})
193
+ main_dict = dfObj.to_dict('records')
194
+
195
+ # if remove_nan:
196
+ # for val, item in enumerate(main_dict):
197
+ # for sub_item, value in item.items():
198
+ # if pd.isna(value):
199
+ # main_dict[val][sub_item] = None
200
+ # else:
201
+ # main_dict[val][sub_item] = value
198
202
 
199
203
  query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, params)
200
204
  self.execute_many(query, main_dict)
File without changes