msb-rpa 0.1.0__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.
- msb_rpa-0.1.0/LICENSE +21 -0
- msb_rpa-0.1.0/PKG-INFO +45 -0
- msb_rpa-0.1.0/README.md +5 -0
- msb_rpa-0.1.0/msb_rpa/__init__.py +0 -0
- msb_rpa-0.1.0/msb_rpa/dato_og_tid.py +64 -0
- msb_rpa-0.1.0/msb_rpa/generelt.py +95 -0
- msb_rpa-0.1.0/msb_rpa/logins.py +163 -0
- msb_rpa-0.1.0/msb_rpa/web.py +72 -0
- msb_rpa-0.1.0/msb_rpa.egg-info/PKG-INFO +45 -0
- msb_rpa-0.1.0/msb_rpa.egg-info/SOURCES.txt +14 -0
- msb_rpa-0.1.0/msb_rpa.egg-info/dependency_links.txt +1 -0
- msb_rpa-0.1.0/msb_rpa.egg-info/requires.txt +6 -0
- msb_rpa-0.1.0/msb_rpa.egg-info/top_level.txt +3 -0
- msb_rpa-0.1.0/pyproject.toml +28 -0
- msb_rpa-0.1.0/setup.cfg +4 -0
- msb_rpa-0.1.0/tests/__init__.py +0 -0
msb_rpa-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 lfrmipypi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
msb_rpa-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: msb_rpa
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Login metoder og diverse hjælper funktioner til RPA projekter
|
|
5
|
+
Author-email: Michael Fredslund Larsen <lfrmi@aarhus.dk>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 lfrmipypi
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Classifier: Programming Language :: Python :: 3
|
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
30
|
+
Classifier: Operating System :: OS Independent
|
|
31
|
+
Requires-Python: >=3.7
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Requires-Dist: pyodbc==5.0.1
|
|
35
|
+
Requires-Dist: selenium==4.14.0
|
|
36
|
+
Requires-Dist: pyperclip==1.8.2
|
|
37
|
+
Requires-Dist: pyautogui==0.9.54
|
|
38
|
+
Requires-Dist: pywinauto==0.6.8
|
|
39
|
+
Requires-Dist: requests==2.31.0
|
|
40
|
+
|
|
41
|
+
# Introduction
|
|
42
|
+
This is a collection of functions generally used in RPA projects in AAK MSB.
|
|
43
|
+
|
|
44
|
+
# Getting Started
|
|
45
|
+
Use pip install aak_msb_generelt and import any function relevant in the current file.
|
msb_rpa-0.1.0/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module for handling date and time related operations.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def month_conversion(month_name):
|
|
7
|
+
"""
|
|
8
|
+
Converts a Danish month name to its corresponding numeric value.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
month_name (str): The name of the month in Danish (e.g., 'januar', 'februar').
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
int: The numeric value of the month (1-12).
|
|
15
|
+
|
|
16
|
+
Raises:
|
|
17
|
+
ValueError: If the month name is not valid.
|
|
18
|
+
"""
|
|
19
|
+
months = {
|
|
20
|
+
'januar': 1, 'februar': 2, 'marts': 3, 'april': 4, 'maj': 5, 'juni': 6,
|
|
21
|
+
'juli': 7, 'august': 8, 'september': 9, 'oktober': 10, 'november': 11, 'december': 12
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
month_name = month_name.lower().strip()
|
|
25
|
+
|
|
26
|
+
if month_name not in months:
|
|
27
|
+
raise ValueError(f"Invalid month name: {month_name}")
|
|
28
|
+
|
|
29
|
+
return months[month_name]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_last_day_of_month(year, month):
|
|
33
|
+
"""
|
|
34
|
+
Finds the last day of a given month for a given year.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
year (int): The year (e.g., 2024).
|
|
38
|
+
month (int): The numeric month (1-12).
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
int: The last day of the month (28-31).
|
|
42
|
+
|
|
43
|
+
Raises:
|
|
44
|
+
ValueError: If the month is out of range (not between 1 and 12).
|
|
45
|
+
"""
|
|
46
|
+
if not 1 <= month <= 12:
|
|
47
|
+
raise ValueError(f"Invalid month: {month}. Month must be between 1 and 12.")
|
|
48
|
+
|
|
49
|
+
num_days_in_month = [31, 29 if _is_leap_year(year) else 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
50
|
+
|
|
51
|
+
return num_days_in_month[month - 1]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _is_leap_year(year):
|
|
55
|
+
"""
|
|
56
|
+
Determines if a given year is a leap year.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
year (int): The year to check.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
bool: True if the year is a leap year, False otherwise.
|
|
63
|
+
"""
|
|
64
|
+
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module for inserting data into ResultTable
|
|
3
|
+
"""
|
|
4
|
+
import time
|
|
5
|
+
import socket
|
|
6
|
+
import pyodbc
|
|
7
|
+
from msb_rpa.web import close_website_panes
|
|
8
|
+
from msb_rpa.web import get_driver()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def sql_insert_result(rpa_id: str,
|
|
12
|
+
executionid: str,
|
|
13
|
+
resulttype: str,
|
|
14
|
+
resultinjson: str,
|
|
15
|
+
conn_str: str,
|
|
16
|
+
resulttable: str):
|
|
17
|
+
"""
|
|
18
|
+
Inserts a row into the given result table using the provided connection.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
rpa_id (str): GUID for the RPA process.
|
|
22
|
+
executionid (str): GUID for the execution.
|
|
23
|
+
resulttype (str): Indicates the type of result.
|
|
24
|
+
resultinjson (str): Result in JSON format.
|
|
25
|
+
conn_str (str): Connection string for the database.
|
|
26
|
+
resulttable (str): Table name in the format [schema].[table].
|
|
27
|
+
|
|
28
|
+
Note:
|
|
29
|
+
- `rpa_id` and `executionid` should be GUIDs in string format (e.g., str(uuid.uuid4())).
|
|
30
|
+
- If `resulttype` is '1', `resultinjson` is converted to: {"Maskine":"<hostname>"}.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
# Convert result to default format if resulttype is '1'
|
|
34
|
+
if resulttype == '1':
|
|
35
|
+
resultinjson = f'{{"Maskine":"{socket.gethostname()}"}}'
|
|
36
|
+
|
|
37
|
+
# Construct the SQL statement
|
|
38
|
+
sql_statement = f'''
|
|
39
|
+
INSERT INTO {resulttable} (RPA_ID, ExecutionID, ResultType, ResultInJson)
|
|
40
|
+
VALUES (?, ?, ?, ?)
|
|
41
|
+
'''
|
|
42
|
+
|
|
43
|
+
# Debugging output
|
|
44
|
+
print("SQL Statement:", sql_statement)
|
|
45
|
+
print("Values:", (rpa_id, executionid, resulttype, resultinjson))
|
|
46
|
+
|
|
47
|
+
# Execute the insert operation
|
|
48
|
+
with pyodbc.connect(conn_str) as connection:
|
|
49
|
+
with connection.cursor() as cursor:
|
|
50
|
+
cursor.execute(sql_statement, (rpa_id, executionid, resulttype, resultinjson))
|
|
51
|
+
connection.commit()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def use_retry_logic(func, *args, max_retries: int = 3, sleep_time: int = 2, target=None, **kwargs):
|
|
55
|
+
"""
|
|
56
|
+
Applies retry logic to a function.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
func (callable): The function to retry.
|
|
60
|
+
*args: Positional arguments to pass to the function.
|
|
61
|
+
max_retries (int): Maximum number of retries (0-5). Default is 3.
|
|
62
|
+
sleep_time (int): Time to sleep between retries in seconds. Default is 2.
|
|
63
|
+
target (str, optional): The target to match against window title or URL for closing specific windows.
|
|
64
|
+
If None, all windows will be closed.
|
|
65
|
+
**kwargs: Keyword arguments to pass to the function.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
driver = get_driver()
|
|
69
|
+
|
|
70
|
+
class BusinessError(Exception):
|
|
71
|
+
"""An empty exception used to identify errors caused by breaking business rules"""
|
|
72
|
+
|
|
73
|
+
if not (0 <= max_retries <= 5):
|
|
74
|
+
raise ValueError("max_retries must be between 0 and 5")
|
|
75
|
+
|
|
76
|
+
last_exception = None
|
|
77
|
+
for attempt in range(max_retries + 1):
|
|
78
|
+
try:
|
|
79
|
+
return func(*args, **kwargs)
|
|
80
|
+
except BusinessError as e:
|
|
81
|
+
print(f"Business error occurred: {e}")
|
|
82
|
+
# Do not retry for business errors
|
|
83
|
+
raise BusinessError(e) from e
|
|
84
|
+
except Exception as e:
|
|
85
|
+
print(f"Process failed on attempt {attempt + 1}: {e}")
|
|
86
|
+
last_exception = e
|
|
87
|
+
|
|
88
|
+
if attempt < max_retries:
|
|
89
|
+
print("Retrying...")
|
|
90
|
+
close_website_panes(driver, target=target)
|
|
91
|
+
time.sleep(sleep_time)
|
|
92
|
+
else:
|
|
93
|
+
print("All retries failed.")
|
|
94
|
+
close_website_panes(driver, target=target)
|
|
95
|
+
raise Exception(f"Failed after {max_retries} retries: {last_exception}")
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Login Module
|
|
3
|
+
|
|
4
|
+
This module contains functions for logging into various systems and applications,
|
|
5
|
+
including Fasit, KMD BogV, and Opus.
|
|
6
|
+
|
|
7
|
+
Dependencies:
|
|
8
|
+
- Selenium
|
|
9
|
+
- Pywinauto
|
|
10
|
+
- Pyautogui
|
|
11
|
+
"""
|
|
12
|
+
import os
|
|
13
|
+
import time
|
|
14
|
+
from selenium.webdriver.common.by import By
|
|
15
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
16
|
+
from selenium.webdriver.support import expected_conditions as EC
|
|
17
|
+
from pywinauto import Application, findwindows
|
|
18
|
+
import pyautogui
|
|
19
|
+
from msb_rpa.web import get_driver
|
|
20
|
+
|
|
21
|
+
# Constants
|
|
22
|
+
WINDOWS_USERNAME = os.getenv('USERNAME')
|
|
23
|
+
DOWNLOAD_DIRECTORY = f"C:\\Users\\{WINDOWS_USERNAME}\\Downloads"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def fasit_login(username: str, password: str, timers=None) -> bool:
|
|
27
|
+
"""
|
|
28
|
+
Logger ind i Fasit (https://login.fasit.dk/aarhus/aak) ved at indtaste brugernavn og password
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
username (str): Fasit username.
|
|
32
|
+
password (str): Fasit password.
|
|
33
|
+
timers (str): Pass in timers extracted from OpenOrchestrator. If not default value is: timers = {"sleep_time": 2, "long_sleep_time": 5, "wait_time": 15, "long_wait_time": 30}
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
bool: True if the login was succesful, else False.
|
|
37
|
+
"""
|
|
38
|
+
if timers is None:
|
|
39
|
+
timers = {"sleep_time": 2, "long_sleep_time": 5, "wait_time": 15, "long_wait_time": 30}
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
url = "https://login.fasit.dk/aarhus/aak"
|
|
43
|
+
driver = get_driver()
|
|
44
|
+
driver.get(url)
|
|
45
|
+
driver.maximize_window()
|
|
46
|
+
wait = WebDriverWait(driver, timers["wait_time"])
|
|
47
|
+
|
|
48
|
+
# BRUGERNAVN INDTASTES.
|
|
49
|
+
element = wait.until(EC.visibility_of_element_located((By.NAME, "loginfmt")))
|
|
50
|
+
element.send_keys(username)
|
|
51
|
+
time.sleep(timers["sleep_time"])
|
|
52
|
+
|
|
53
|
+
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='submit']")))
|
|
54
|
+
element.click()
|
|
55
|
+
time.sleep(timers["sleep_time"])
|
|
56
|
+
|
|
57
|
+
# PASSWORD INDTASTES.
|
|
58
|
+
element = wait.until(EC.visibility_of_element_located((By.NAME, "passwd")))
|
|
59
|
+
element.send_keys(password)
|
|
60
|
+
|
|
61
|
+
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='submit']")))
|
|
62
|
+
element.click()
|
|
63
|
+
|
|
64
|
+
search = wait.until(EC.presence_of_element_located((By.XPATH, '//div[@class="layout__app-header"]//div[@class="MuiBox-root css-0"]')))
|
|
65
|
+
logged_in_tekst = search.text
|
|
66
|
+
print(logged_in_tekst)
|
|
67
|
+
|
|
68
|
+
return True
|
|
69
|
+
|
|
70
|
+
except Exception:
|
|
71
|
+
return False
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def bogv_login(username, password):
|
|
75
|
+
"""
|
|
76
|
+
Logger ind i KMD BogV windows applikationen.
|
|
77
|
+
|
|
78
|
+
Parameters:
|
|
79
|
+
username (str): The username for login.
|
|
80
|
+
password (str): The password for login.
|
|
81
|
+
|
|
82
|
+
Requirements:
|
|
83
|
+
- KMD BogV must be installed at the default path.
|
|
84
|
+
- Requires `pywinauto` and `pyautogui` libraries.
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
program_path = r'C:\Program Files (x86)\KMD\BogV\BogV.exe'
|
|
88
|
+
app = Application(backend='uia').start(program_path, timeout=10)
|
|
89
|
+
app = Application(backend="uia").connect(title="Tilslutning til KMD", class_name="ThunderRT6FormDC")
|
|
90
|
+
|
|
91
|
+
kmd_bogv = app.window(title="Tilslutning til KMD", class_name="ThunderRT6FormDC")
|
|
92
|
+
kmd_bogv.set_focus()
|
|
93
|
+
|
|
94
|
+
brugernavn = kmd_bogv.child_window(auto_id='7')
|
|
95
|
+
brugernavn.click_input()
|
|
96
|
+
pyautogui.typewrite(username, interval=0.1)
|
|
97
|
+
|
|
98
|
+
passwordfelt = kmd_bogv.child_window(auto_id='6')
|
|
99
|
+
passwordfelt.click_input()
|
|
100
|
+
pyautogui.typewrite(password, interval=0.1)
|
|
101
|
+
|
|
102
|
+
loginknap = kmd_bogv.child_window(title="Logon", auto_id="4", control_type="Button")
|
|
103
|
+
loginknap.click_input()
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# Opus Login
|
|
107
|
+
def opus_login(username: str, password: str):
|
|
108
|
+
"""
|
|
109
|
+
Logs into the Opus system via the web and performs additional steps.
|
|
110
|
+
|
|
111
|
+
Parameters:
|
|
112
|
+
username (str): The username for login.
|
|
113
|
+
password (str): The password for login.
|
|
114
|
+
"""
|
|
115
|
+
driver = get_driver()
|
|
116
|
+
|
|
117
|
+
wait = WebDriverWait(driver, 10)
|
|
118
|
+
url = "https://portal.kmd.dk/irj/portal"
|
|
119
|
+
|
|
120
|
+
driver.get(url)
|
|
121
|
+
driver.maximize_window()
|
|
122
|
+
|
|
123
|
+
element = wait.until(EC.visibility_of_element_located((By.ID, "logonuidfield")))
|
|
124
|
+
element.send_keys(username)
|
|
125
|
+
|
|
126
|
+
element = wait.until(EC.visibility_of_element_located((By.ID, "logonpassfield")))
|
|
127
|
+
element.send_keys(password)
|
|
128
|
+
|
|
129
|
+
element = wait.until(EC.element_to_be_clickable((By.ID, "buttonLogon")))
|
|
130
|
+
element.click()
|
|
131
|
+
|
|
132
|
+
xpath_expression = '//div[@displayname="Mine Genveje" and starts-with(@id, "tabIndex")]'
|
|
133
|
+
element = wait.until(EC.element_to_be_clickable((By.XPATH, xpath_expression)))
|
|
134
|
+
element.click()
|
|
135
|
+
|
|
136
|
+
time.sleep(5)
|
|
137
|
+
files = os.listdir(DOWNLOAD_DIRECTORY)
|
|
138
|
+
for file in files:
|
|
139
|
+
if file.endswith("tx.sap"):
|
|
140
|
+
os.system(f"start {DOWNLOAD_DIRECTORY}\\{file}")
|
|
141
|
+
break
|
|
142
|
+
|
|
143
|
+
_opus_aabn()
|
|
144
|
+
driver.quit()
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _opus_aabn():
|
|
148
|
+
"""
|
|
149
|
+
Handles opening and interacting with the SAP window after Opus login.
|
|
150
|
+
"""
|
|
151
|
+
sap_window_title = "Information"
|
|
152
|
+
time.sleep(10)
|
|
153
|
+
sap_window_handle = findwindows.find_window(title=sap_window_title)
|
|
154
|
+
sap_window_gw = Application(backend="uia").connect(handle=sap_window_handle)
|
|
155
|
+
sap_app_window = sap_window_gw.window(title=sap_window_title, handle=sap_window_handle)
|
|
156
|
+
sap_app_window.set_focus()
|
|
157
|
+
|
|
158
|
+
app_toolbar = sap_app_window.child_window(title="AppToolbar")
|
|
159
|
+
if app_toolbar:
|
|
160
|
+
fortset_button = app_toolbar.child_window(title="Fortsæt")
|
|
161
|
+
fortset_button.wait("enabled", timeout=10)
|
|
162
|
+
if fortset_button:
|
|
163
|
+
fortset_button.click_input()
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module for managing browser tabs and WebDriver operations using Selenium.
|
|
3
|
+
"""
|
|
4
|
+
import re
|
|
5
|
+
from selenium import webdriver
|
|
6
|
+
from selenium.webdriver.chrome.options import Options
|
|
7
|
+
|
|
8
|
+
driver = None
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_driver():
|
|
12
|
+
"""Global webdriver"""
|
|
13
|
+
global driver
|
|
14
|
+
if driver is None:
|
|
15
|
+
chrome_options = Options()
|
|
16
|
+
chrome_options.add_argument("--disable-search-engine-choice-screen")
|
|
17
|
+
driver = webdriver.Chrome(options=chrome_options)
|
|
18
|
+
return driver
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def pick_website_pane(driver: webdriver, target: str) -> bool:
|
|
22
|
+
"""
|
|
23
|
+
Switches to the browser tab that matches the target URL or title of the pane.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
driver (webdriver): The Selenium WebDriver instance.
|
|
27
|
+
target (str): The target URL/title to find in open browser tabs.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
bool: True if a tab with the target URL/title is found and switched to, False otherwise.
|
|
31
|
+
"""
|
|
32
|
+
window_handles = driver.window_handles
|
|
33
|
+
|
|
34
|
+
for handle in window_handles:
|
|
35
|
+
driver.switch_to.window(handle)
|
|
36
|
+
if isinstance(target, str):
|
|
37
|
+
if target.lower() in driver.title.lower():
|
|
38
|
+
return True # Successfully switched to the new window
|
|
39
|
+
else:
|
|
40
|
+
if target in driver.current_url:
|
|
41
|
+
return True # Successfully switched to the new window
|
|
42
|
+
|
|
43
|
+
return False # No window with the target URL or title found
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def close_website_panes(driver: webdriver, target=None):
|
|
47
|
+
"""
|
|
48
|
+
Closes browser windows based on the provided target, or all windows if no target is specified.
|
|
49
|
+
Searches for the target in both window titles and URLs.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
driver (webdriver): The Selenium WebDriver instance.
|
|
53
|
+
target (str, optional): The target to match against window title or URL.
|
|
54
|
+
If None, all windows will be closed.
|
|
55
|
+
"""
|
|
56
|
+
handles_to_close = []
|
|
57
|
+
|
|
58
|
+
for handle in driver.window_handles:
|
|
59
|
+
driver.switch_to.window(handle)
|
|
60
|
+
if target is None or (target and (re.search(target, driver.title) or re.search(target, driver.current_url))):
|
|
61
|
+
print(f"Marking for closure: Title '{driver.title}', URL '{driver.current_url}'")
|
|
62
|
+
handles_to_close.append(handle)
|
|
63
|
+
|
|
64
|
+
for handle in handles_to_close:
|
|
65
|
+
driver.switch_to.window(handle)
|
|
66
|
+
driver.close()
|
|
67
|
+
|
|
68
|
+
if driver.window_handles:
|
|
69
|
+
driver.switch_to.window(driver.window_handles[0])
|
|
70
|
+
else:
|
|
71
|
+
print("All windows closed.")
|
|
72
|
+
driver = None
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: msb_rpa
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Login metoder og diverse hjælper funktioner til RPA projekter
|
|
5
|
+
Author-email: Michael Fredslund Larsen <lfrmi@aarhus.dk>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 lfrmipypi
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Classifier: Programming Language :: Python :: 3
|
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
30
|
+
Classifier: Operating System :: OS Independent
|
|
31
|
+
Requires-Python: >=3.7
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Requires-Dist: pyodbc==5.0.1
|
|
35
|
+
Requires-Dist: selenium==4.14.0
|
|
36
|
+
Requires-Dist: pyperclip==1.8.2
|
|
37
|
+
Requires-Dist: pyautogui==0.9.54
|
|
38
|
+
Requires-Dist: pywinauto==0.6.8
|
|
39
|
+
Requires-Dist: requests==2.31.0
|
|
40
|
+
|
|
41
|
+
# Introduction
|
|
42
|
+
This is a collection of functions generally used in RPA projects in AAK MSB.
|
|
43
|
+
|
|
44
|
+
# Getting Started
|
|
45
|
+
Use pip install aak_msb_generelt and import any function relevant in the current file.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
msb_rpa/__init__.py
|
|
5
|
+
msb_rpa/dato_og_tid.py
|
|
6
|
+
msb_rpa/generelt.py
|
|
7
|
+
msb_rpa/logins.py
|
|
8
|
+
msb_rpa/web.py
|
|
9
|
+
msb_rpa.egg-info/PKG-INFO
|
|
10
|
+
msb_rpa.egg-info/SOURCES.txt
|
|
11
|
+
msb_rpa.egg-info/dependency_links.txt
|
|
12
|
+
msb_rpa.egg-info/requires.txt
|
|
13
|
+
msb_rpa.egg-info/top_level.txt
|
|
14
|
+
tests/__init__.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=45", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "msb_rpa"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Login metoder og diverse hjælper funktioner til RPA projekter"
|
|
9
|
+
authors = [{name = "Michael Fredslund Larsen", email = "lfrmi@aarhus.dk"}]
|
|
10
|
+
license = {file = "LICENSE"}
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.7"
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"pyodbc == 5.0.1",
|
|
20
|
+
"selenium == 4.14.0",
|
|
21
|
+
"pyperclip == 1.8.2",
|
|
22
|
+
"pyautogui == 0.9.54",
|
|
23
|
+
"pywinauto == 0.6.8",
|
|
24
|
+
"requests == 2.31.0"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
where = ["."]
|
msb_rpa-0.1.0/setup.cfg
ADDED
|
File without changes
|