ITK-dev-shared-components 2.4.0__tar.gz → 2.5.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.
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/PKG-INFO +3 -1
- itk_dev_shared_components-2.5.0/itk_dev_shared_components/eflyt/eflyt_case.py +118 -0
- itk_dev_shared_components-2.5.0/itk_dev_shared_components/eflyt/eflyt_login.py +29 -0
- itk_dev_shared_components-2.5.0/itk_dev_shared_components/eflyt/eflyt_search.py +100 -0
- itk_dev_shared_components-2.5.0/itk_dev_shared_components/eflyt/eflyt_util.py +7 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/kmd_nova/nova_notes.py +3 -0
- itk_dev_shared_components-2.5.0/itk_dev_shared_components/misc/address_lookup.py +80 -0
- itk_dev_shared_components-2.5.0/itk_dev_shared_components/misc/cvr_lookup.py +174 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/misc/file_util.py +14 -0
- itk_dev_shared_components-2.5.0/itk_dev_shared_components/smtp/__init__.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components.egg-info/PKG-INFO +3 -1
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components.egg-info/SOURCES.txt +7 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components.egg-info/requires.txt +2 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/pyproject.toml +3 -1
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/LICENSE +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/README.md +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/__init__.py +0 -0
- {itk_dev_shared_components-2.4.0/itk_dev_shared_components/graph → itk_dev_shared_components-2.5.0/itk_dev_shared_components/eflyt}/__init__.py +0 -0
- {itk_dev_shared_components-2.4.0/itk_dev_shared_components/misc → itk_dev_shared_components-2.5.0/itk_dev_shared_components/graph}/__init__.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/graph/authentication.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/graph/common.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/graph/file.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/graph/mail.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/graph/site.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/kmd_nova/__init__.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/kmd_nova/authentication.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/kmd_nova/cpr.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/kmd_nova/nova_cases.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/kmd_nova/nova_documents.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/kmd_nova/nova_objects.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/kmd_nova/nova_tasks.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/kmd_nova/util.py +0 -0
- {itk_dev_shared_components-2.4.0/itk_dev_shared_components/sap → itk_dev_shared_components-2.5.0/itk_dev_shared_components/misc}/__init__.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/misc/cpr_util.py +0 -0
- {itk_dev_shared_components-2.4.0/itk_dev_shared_components/smtp → itk_dev_shared_components-2.5.0/itk_dev_shared_components/sap}/__init__.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/sap/fmcacov.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/sap/gridview_util.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/sap/multi_session.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/sap/opret_kundekontakt.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/sap/sap_login.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/sap/sap_util.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/sap/tree_util.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components/smtp/smtp_util.py +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components.egg-info/dependency_links.txt +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/itk_dev_shared_components.egg-info/top_level.txt +0 -0
- {itk_dev_shared_components-2.4.0 → itk_dev_shared_components-2.5.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: itk_dev_shared_components
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.5.0
|
|
4
4
|
Summary: Shared components to use in RPA projects
|
|
5
5
|
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
6
|
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
@@ -15,6 +15,8 @@ Requires-Dist: pywin32>=306
|
|
|
15
15
|
Requires-Dist: msal>=1.24.1
|
|
16
16
|
Requires-Dist: requests>=2.31.0
|
|
17
17
|
Requires-Dist: beautifulsoup4>=4.12.2
|
|
18
|
+
Requires-Dist: selenium==4.16.0
|
|
19
|
+
Requires-Dist: uiautomation==2.0.18
|
|
18
20
|
Provides-Extra: dev
|
|
19
21
|
Requires-Dist: python-dotenv; extra == "dev"
|
|
20
22
|
Requires-Dist: flake8; extra == "dev"
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Module for handling cases in eFlyt"""
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from datetime import date, datetime
|
|
4
|
+
|
|
5
|
+
from selenium import webdriver
|
|
6
|
+
from selenium.webdriver.common.by import By
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Case:
|
|
11
|
+
"""A dataclass representing an Eflyt case."""
|
|
12
|
+
case_number: str
|
|
13
|
+
deadline: date | None
|
|
14
|
+
case_types: list[str]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class Inhabitant:
|
|
19
|
+
"""A dataclass representing an inhabitant."""
|
|
20
|
+
cpr: str
|
|
21
|
+
name: str
|
|
22
|
+
move_in_date: date
|
|
23
|
+
relations: list[str]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class Applicant:
|
|
28
|
+
"""A dataclass representing an applicant."""
|
|
29
|
+
cpr: str
|
|
30
|
+
name: str
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_beboere(browser: webdriver.Chrome) -> list[Inhabitant]:
|
|
34
|
+
"""Get a list of current inhabitants on the case currently open.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
browser: The webdriver browser object.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
A list of Inhabitants.
|
|
41
|
+
"""
|
|
42
|
+
# Go to the correct tab and scrape data
|
|
43
|
+
change_tab(browser, 1)
|
|
44
|
+
beboer_table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_becPersonTab_GridViewBeboere")
|
|
45
|
+
rows = beboer_table.find_elements(By.TAG_NAME, "tr")
|
|
46
|
+
|
|
47
|
+
# Remove header
|
|
48
|
+
rows.pop(0)
|
|
49
|
+
|
|
50
|
+
inhabitants = []
|
|
51
|
+
for inhabitant in rows:
|
|
52
|
+
# Get date for moving in, CPR and name
|
|
53
|
+
moving_in = datetime.strptime(inhabitant.find_element(By.XPATH, "td[1]/span | td[1]/a").text, "%d-%m-%Y").date()
|
|
54
|
+
cpr = inhabitant.find_element(By.XPATH, "td[2]").text.replace("-", "")
|
|
55
|
+
name = inhabitant.find_element(By.XPATH, "td[3]").text
|
|
56
|
+
|
|
57
|
+
# Check for a list of relations
|
|
58
|
+
relations = []
|
|
59
|
+
elements = inhabitant.find_elements(By.XPATH, "td[4]/span")
|
|
60
|
+
if elements:
|
|
61
|
+
relations = elements[0].text.replace("<br>", ";").replace("\n", ";").split(";")
|
|
62
|
+
|
|
63
|
+
# Create an Inhabitant and add to list
|
|
64
|
+
new_inhabitant = Inhabitant(cpr, name, moving_in, relations)
|
|
65
|
+
inhabitants.append(new_inhabitant)
|
|
66
|
+
|
|
67
|
+
return inhabitants
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def get_room_count(browser: webdriver.Chrome) -> int:
|
|
71
|
+
"""Get the number of rooms on the address.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
browser: The webdriver browser object.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
The number of rooms on the address.
|
|
78
|
+
"""
|
|
79
|
+
change_tab(browser, 1)
|
|
80
|
+
area_room_text = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab6_lblAreaText").text
|
|
81
|
+
room_text = area_room_text.split("/")[1]
|
|
82
|
+
return int(room_text)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def get_applicants(browser: webdriver.Chrome) -> list[Applicant]:
|
|
86
|
+
"""Get a list of applicants' cpr numbers from the applicant table.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
browser: The webdriver browser object.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
A list of cpr numbers.
|
|
93
|
+
"""
|
|
94
|
+
table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewMovingPersons")
|
|
95
|
+
rows = table.find_elements(By.TAG_NAME, "tr")
|
|
96
|
+
|
|
97
|
+
# Remove header row
|
|
98
|
+
rows.pop(0)
|
|
99
|
+
|
|
100
|
+
applicants = []
|
|
101
|
+
|
|
102
|
+
for row in rows:
|
|
103
|
+
cpr = row.find_element(By.XPATH, "td[2]/a[2]").text.replace("-", "")
|
|
104
|
+
name = row.find_element(By.XPATH, "td[3]/a").text
|
|
105
|
+
applicant = Applicant(cpr, name)
|
|
106
|
+
applicants.append(applicant)
|
|
107
|
+
|
|
108
|
+
return applicants
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def change_tab(browser: webdriver.Chrome, tab_index: int):
|
|
112
|
+
"""Change the tab in the case view e.g. 'Sagslog', 'Breve'.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
browser: The webdriver browser object.
|
|
116
|
+
tab_index: The zero-based index of the tab to select.
|
|
117
|
+
"""
|
|
118
|
+
browser.execute_script(f"__doPostBack('ctl00$ContentPlaceHolder2$ptFanePerson$ImgJournalMap','{tab_index}')")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Module for logging into Eflyt/Daedalus/Whatchamacallit using Selenium"""
|
|
2
|
+
from selenium import webdriver
|
|
3
|
+
from selenium.webdriver.common.by import By
|
|
4
|
+
from selenium.common.exceptions import NoSuchElementException
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def login(username: str, password: str) -> webdriver.Chrome:
|
|
8
|
+
"""Log into Eflyt using a password and username.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
username: Username for login.
|
|
12
|
+
password: Password for login.
|
|
13
|
+
"""
|
|
14
|
+
chrome_options = webdriver.ChromeOptions()
|
|
15
|
+
chrome_options.add_argument("--disable-search-engine-choice-screen")
|
|
16
|
+
browser = webdriver.Chrome(options=chrome_options)
|
|
17
|
+
browser.maximize_window()
|
|
18
|
+
|
|
19
|
+
browser.get("https://notuskommunal.scandihealth.net/")
|
|
20
|
+
browser.find_element(By.ID, "Login1_UserName").send_keys(username)
|
|
21
|
+
browser.find_element(By.ID, "Login1_Password").send_keys(password)
|
|
22
|
+
browser.find_element(By.ID, "Login1_LoginImageButton").click()
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
browser.find_element(By.ID, "ctl00_imgLogo")
|
|
26
|
+
except NoSuchElementException as exc:
|
|
27
|
+
raise RuntimeError("Login failed") from exc
|
|
28
|
+
|
|
29
|
+
return browser
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Interface for working with the 'Digital Flytning' section of Eflyt"""
|
|
2
|
+
from datetime import date, datetime
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from selenium import webdriver
|
|
6
|
+
from selenium.webdriver.common.by import By
|
|
7
|
+
from selenium.webdriver.support.select import Select
|
|
8
|
+
|
|
9
|
+
from itk_dev_shared_components.eflyt.eflyt_util import format_date
|
|
10
|
+
from itk_dev_shared_components.eflyt.eflyt_case import Case
|
|
11
|
+
|
|
12
|
+
CaseState = Literal[
|
|
13
|
+
"Alle",
|
|
14
|
+
"Afsluttet",
|
|
15
|
+
"Fraflytning",
|
|
16
|
+
"I gang",
|
|
17
|
+
"Ubehandlet"
|
|
18
|
+
]
|
|
19
|
+
CaseStatus = Literal[
|
|
20
|
+
"(vælg status)",
|
|
21
|
+
"Afsluttet",
|
|
22
|
+
"Afventer CPR",
|
|
23
|
+
"Afvist",
|
|
24
|
+
"Fejl",
|
|
25
|
+
"Godkendt",
|
|
26
|
+
"I gang",
|
|
27
|
+
"Partshøring",
|
|
28
|
+
"Sendt til CPR",
|
|
29
|
+
"Svarfrist overskredet",
|
|
30
|
+
"Ubehandlet"
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def search(browser: webdriver.Chrome, from_date: date | None = None, to_date: date | None = None, case_state: CaseState = "Alle", case_status: CaseStatus = "(vælg status)"):
|
|
35
|
+
"""Apply the correct filters in Eflyt and search the case list.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
browser: The webdriver browser object.
|
|
39
|
+
"""
|
|
40
|
+
browser.get("https://notuskommunal.scandihealth.net/web/SearchResulteFlyt.aspx")
|
|
41
|
+
Select(browser.find_element(By.ID, "ctl00_ContentPlaceHolder1_SearchControl_ddlTilstand")).select_by_visible_text(case_state)
|
|
42
|
+
Select(browser.find_element(By.ID, "ctl00_ContentPlaceHolder1_SearchControl_ddlStatus")).select_by_visible_text(case_status)
|
|
43
|
+
if from_date:
|
|
44
|
+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder1_SearchControl_txtFlytteStartDato").send_keys(format_date(from_date))
|
|
45
|
+
if to_date:
|
|
46
|
+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder1_SearchControl_txtFlytteEndDato").send_keys(format_date(to_date))
|
|
47
|
+
browser.find_element(By.XPATH, '//input[contains(@id, "earchControl_btnSearch")]').click()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def extract_cases(browser: webdriver.Chrome) -> list[Case]:
|
|
51
|
+
"""Extract and filter cases from the case table. Requires a search to have been performed immediately before.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
browser: The webdriver browser object.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
A list of filtered case objects.
|
|
58
|
+
"""
|
|
59
|
+
table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewSearchResult")
|
|
60
|
+
rows = table.find_elements(By.TAG_NAME, "tr")
|
|
61
|
+
# Remove header row
|
|
62
|
+
rows.pop(0)
|
|
63
|
+
cases = []
|
|
64
|
+
for row in rows:
|
|
65
|
+
deadline = row.find_element(By.XPATH, "td[3]/a").text
|
|
66
|
+
|
|
67
|
+
# Convert deadline to date object
|
|
68
|
+
if deadline:
|
|
69
|
+
deadline = datetime.strptime(deadline, "%d-%m-%Y")
|
|
70
|
+
else:
|
|
71
|
+
deadline = None
|
|
72
|
+
|
|
73
|
+
case_number = row.find_element(By.XPATH, "td[4]").text
|
|
74
|
+
case_types_text = row.find_element(By.XPATH, "td[5]").text
|
|
75
|
+
|
|
76
|
+
# If the case types ends with '...' we need to get the title instead
|
|
77
|
+
if case_types_text.endswith("..."):
|
|
78
|
+
case_types_text = row.find_element(By.XPATH, "td[5]").get_attribute("Title")
|
|
79
|
+
|
|
80
|
+
case_types = case_types_text.split(", ")
|
|
81
|
+
case = Case(case_number, deadline, case_types)
|
|
82
|
+
cases.append(case)
|
|
83
|
+
|
|
84
|
+
return cases
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def open_case(browser: webdriver.Chrome, case: str):
|
|
88
|
+
"""Open a case by searching for its case number.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
browser: The webdriver browser object.
|
|
92
|
+
case: The case to open.
|
|
93
|
+
"""
|
|
94
|
+
# The id for both the search field and search button changes based on the current view hence the weird selectors.
|
|
95
|
+
browser.get("https://notuskommunal.scandihealth.net/web/SearchResulteFlyt.aspx")
|
|
96
|
+
case_input = browser.find_element(By.ID, 'ctl00_ContentPlaceHolder1_SearchControl_txtSagNr')
|
|
97
|
+
case_input.clear()
|
|
98
|
+
case_input.send_keys(case)
|
|
99
|
+
|
|
100
|
+
browser.find_element(By.ID, 'ctl00_ContentPlaceHolder1_SearchControl_btnSearch').click()
|
|
@@ -69,6 +69,7 @@ def _encode_text(string: str) -> str:
|
|
|
69
69
|
Ensure the base64 string doesn't contain padding by inserting spaces at the end of the input string.
|
|
70
70
|
There is a bug in the Nova api that corrupts the string if it contains padding.
|
|
71
71
|
The extra spaces will not show up in the Nova user interface.
|
|
72
|
+
A necessary hack has been implemented to convert Æ, Ø and Å to ae, oe and aa.
|
|
72
73
|
|
|
73
74
|
Args:
|
|
74
75
|
string: The string to encode.
|
|
@@ -76,6 +77,8 @@ def _encode_text(string: str) -> str:
|
|
|
76
77
|
Returns:
|
|
77
78
|
A base64 string containing no padding.
|
|
78
79
|
"""
|
|
80
|
+
string = string.replace('æ', 'ae').replace('ø', 'oe').replace('å', 'aa').replace('Æ', 'Ae').replace('Ø', 'Oe').replace('Å', 'Aa')
|
|
81
|
+
|
|
79
82
|
def b64(s: str) -> str:
|
|
80
83
|
"""Helper function to convert a string to base64."""
|
|
81
84
|
return base64.b64encode(s.encode()).decode()
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""This module contains functions to look up addresses in DAWA.
|
|
2
|
+
https://dawadocs.dataforsyningen.dk/dok/api/
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
# pylint: disable-next=too-many-instance-attributes
|
|
12
|
+
class Address:
|
|
13
|
+
"""A dataclass representing an address."""
|
|
14
|
+
street: str
|
|
15
|
+
number: str
|
|
16
|
+
floor: str
|
|
17
|
+
door: str
|
|
18
|
+
minor_city: str
|
|
19
|
+
postal_city: str
|
|
20
|
+
postal_code: str
|
|
21
|
+
municipality_code: str
|
|
22
|
+
address_text: str
|
|
23
|
+
id: str = field(repr=False)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def search_address(query: str | None = None, street: str | None = None, number: str | None = None,
|
|
27
|
+
postal_code: str | None = None, municipality_code: str | None = None,
|
|
28
|
+
results_per_page: int = 100, page: int = 1) -> list[Address]:
|
|
29
|
+
"""Search for an address in the DAWA API.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
query: The free text to search for.
|
|
33
|
+
street: The exact street of the address.
|
|
34
|
+
number: The exact number of the address.
|
|
35
|
+
postal_code: The exact postal code of the address.
|
|
36
|
+
municipality_code: The exact municipality code of the address.
|
|
37
|
+
results_per_page: The number of results to fetch per page.
|
|
38
|
+
page: The 1-based page of results to fetch.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
A list of address objects describing the addresses found.
|
|
42
|
+
"""
|
|
43
|
+
url = "https://api.dataforsyningen.dk/adresser"
|
|
44
|
+
|
|
45
|
+
params = {
|
|
46
|
+
'struktur': 'mini',
|
|
47
|
+
'per_side': results_per_page,
|
|
48
|
+
'side': page
|
|
49
|
+
}
|
|
50
|
+
if query:
|
|
51
|
+
params['q'] = query
|
|
52
|
+
if street:
|
|
53
|
+
params['vejnavn'] = street
|
|
54
|
+
if number:
|
|
55
|
+
params['husnr'] = number
|
|
56
|
+
if postal_code:
|
|
57
|
+
params['postnr'] = postal_code
|
|
58
|
+
if municipality_code:
|
|
59
|
+
params['kommunekode'] = municipality_code
|
|
60
|
+
|
|
61
|
+
response = requests.get(url, params=params, timeout=10)
|
|
62
|
+
response.raise_for_status()
|
|
63
|
+
|
|
64
|
+
addresses = []
|
|
65
|
+
for a in response.json():
|
|
66
|
+
address = Address(
|
|
67
|
+
street=a['vejnavn'],
|
|
68
|
+
number=a['husnr'],
|
|
69
|
+
floor=a['etage'],
|
|
70
|
+
door=a['dør'],
|
|
71
|
+
minor_city=a['supplerendebynavn'],
|
|
72
|
+
postal_city=a['postnrnavn'],
|
|
73
|
+
postal_code=a['postnr'],
|
|
74
|
+
municipality_code=a['kommunekode'],
|
|
75
|
+
address_text=a['betegnelse'],
|
|
76
|
+
id=a['id']
|
|
77
|
+
)
|
|
78
|
+
addresses.append(address)
|
|
79
|
+
|
|
80
|
+
return addresses
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""This module has functions related to calls
|
|
2
|
+
to the Virk CVR API."""
|
|
3
|
+
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from datetime import date, datetime
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
from requests.auth import HTTPBasicAuth
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class Company:
|
|
13
|
+
"""A dataclass representing a company."""
|
|
14
|
+
cvr: str
|
|
15
|
+
name: str
|
|
16
|
+
founded_date: date
|
|
17
|
+
address: str
|
|
18
|
+
postal_code: str
|
|
19
|
+
city: str
|
|
20
|
+
company_type: str
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def cvr_lookup(cvr: str, username: str, password: str) -> Company:
|
|
24
|
+
"""Look up a company based on a CVR number.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
cvr: The cvr number of the company to look up.
|
|
28
|
+
username: The username to the cvr api.
|
|
29
|
+
password: The password to the cvr api.
|
|
30
|
+
|
|
31
|
+
Raises:
|
|
32
|
+
ValueError: If no company is found on the given cvr number.
|
|
33
|
+
ValueError: If more than one company is found on the given cvr number.
|
|
34
|
+
RuntimeError: If a company with a different cvr number is found.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
A company object describing the found company.
|
|
38
|
+
"""
|
|
39
|
+
url = "http://distribution.virk.dk/cvr-permanent/virksomhed/_search"
|
|
40
|
+
headers = {
|
|
41
|
+
"Content-Type": "application/json"
|
|
42
|
+
}
|
|
43
|
+
auth = HTTPBasicAuth(username, password)
|
|
44
|
+
|
|
45
|
+
data = {
|
|
46
|
+
"_source": ["Vrvirksomhed.virksomhedMetadata", "Vrvirksomhed.cvrNummer"],
|
|
47
|
+
"query": {
|
|
48
|
+
"term": {
|
|
49
|
+
"Vrvirksomhed.cvrNummer": cvr
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
response = requests.post(url, headers=headers, auth=auth, json=data, timeout=5)
|
|
55
|
+
response.raise_for_status()
|
|
56
|
+
|
|
57
|
+
response_json = response.json()
|
|
58
|
+
|
|
59
|
+
if response_json['hits']['total'] == 0:
|
|
60
|
+
raise ValueError("No companies found on the given cvr.")
|
|
61
|
+
if response_json['hits']['total'] > 1:
|
|
62
|
+
raise ValueError("More than one company found on the given cvr.")
|
|
63
|
+
|
|
64
|
+
company_dict = response_json['hits']['hits'][0]['_source']['Vrvirksomhed']
|
|
65
|
+
return _unpack_company_dict(company_dict)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def cvr_mass_lookup(cvr_list: list[str], match_length: bool, username: str, password: str) -> list[Company]:
|
|
69
|
+
"""Look up multiple companies based on a list of cvr numbers.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
cvr_list: The list of cvr numbers to look up.
|
|
73
|
+
match_length: Whether the number results must match the number of inputs.
|
|
74
|
+
username: The username to the cvr api.
|
|
75
|
+
password: The password to the cvr api.
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
ValueError: If match_length is true and the number of results doesn't match.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
A list of company objects describing the found companies.
|
|
82
|
+
The list is sorted to match the input list.
|
|
83
|
+
"""
|
|
84
|
+
url = "http://distribution.virk.dk/cvr-permanent/virksomhed/_search"
|
|
85
|
+
headers = {
|
|
86
|
+
"Content-Type": "application/json"
|
|
87
|
+
}
|
|
88
|
+
auth = HTTPBasicAuth(username, password)
|
|
89
|
+
|
|
90
|
+
data = {
|
|
91
|
+
"_source": ["Vrvirksomhed.virksomhedMetadata", "Vrvirksomhed.cvrNummer"],
|
|
92
|
+
"query": {
|
|
93
|
+
"terms": {
|
|
94
|
+
"Vrvirksomhed.cvrNummer": cvr_list
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
response = requests.post(url, headers=headers, auth=auth, json=data, timeout=5)
|
|
100
|
+
response.raise_for_status()
|
|
101
|
+
|
|
102
|
+
response_json = response.json()
|
|
103
|
+
|
|
104
|
+
if match_length and response_json['hits']['total'] != len(cvr_list):
|
|
105
|
+
raise ValueError(f"The number of companies found didn't match the input list: {len(cvr_list)} != {response_json['hits']['total']}")
|
|
106
|
+
|
|
107
|
+
companies = []
|
|
108
|
+
|
|
109
|
+
for hit in response_json['hits']['hits']:
|
|
110
|
+
company_dict = hit['_source']['Vrvirksomhed']
|
|
111
|
+
companies.append(_unpack_company_dict(company_dict))
|
|
112
|
+
|
|
113
|
+
# Sort to match input list
|
|
114
|
+
companies.sort(key=lambda c: cvr_list.index(c.cvr))
|
|
115
|
+
|
|
116
|
+
return companies
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _unpack_company_dict(company_dict: dict) -> Company:
|
|
120
|
+
"""Unpack a response dict to a company object.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
company_dict: The company dict from the cvr api.
|
|
124
|
+
cvr: The cvr number of the company.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
A company object describing the found company.
|
|
128
|
+
"""
|
|
129
|
+
cvr = str(company_dict['cvrNummer'])
|
|
130
|
+
company_dict = company_dict['virksomhedMetadata']
|
|
131
|
+
address, postal_code, city = _parse_address(company_dict['nyesteBeliggenhedsadresse'])
|
|
132
|
+
|
|
133
|
+
return Company(
|
|
134
|
+
cvr=cvr,
|
|
135
|
+
name=company_dict['nyesteNavn']['navn'],
|
|
136
|
+
founded_date=datetime.strptime(company_dict['stiftelsesDato'], "%Y-%m-%d").date(),
|
|
137
|
+
address=address,
|
|
138
|
+
postal_code=postal_code,
|
|
139
|
+
city=city,
|
|
140
|
+
company_type=company_dict['nyesteVirksomhedsform']['langBeskrivelse']
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _parse_address(address_dict: dict) -> tuple[str, str, str]:
|
|
145
|
+
"""Parse and format the address of a company.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
address_dict: The dictionary describing the address.
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
A tuple of address, postal code and city.
|
|
152
|
+
"""
|
|
153
|
+
address = ""
|
|
154
|
+
|
|
155
|
+
if address_dict['conavn']:
|
|
156
|
+
address += f"C/O {address_dict['conavn']}, "
|
|
157
|
+
|
|
158
|
+
address += address_dict['vejnavn']
|
|
159
|
+
address += f" {address_dict['husnummerFra']}"
|
|
160
|
+
|
|
161
|
+
if address_dict['husnummerTil']:
|
|
162
|
+
address += f"-{address_dict['husnummerTil']}"
|
|
163
|
+
|
|
164
|
+
if address_dict['bogstavFra']:
|
|
165
|
+
address += address_dict['bogstavFra']
|
|
166
|
+
if address_dict['bogstavTil']:
|
|
167
|
+
address += f"-{address_dict['bogstavTil']}"
|
|
168
|
+
|
|
169
|
+
if address_dict['etage']:
|
|
170
|
+
address += f", {address_dict['etage']}."
|
|
171
|
+
if address_dict['sidedoer']:
|
|
172
|
+
address += f" {address_dict['sidedoer']}"
|
|
173
|
+
|
|
174
|
+
return address, str(address_dict['postnummer']), address_dict['postdistrikt']
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import os
|
|
4
4
|
import time
|
|
5
5
|
|
|
6
|
+
import uiautomation
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
def wait_for_download(folder: str, file_name: str | None, file_extension: str, timeout: int = 10) -> str:
|
|
8
10
|
"""Wait for a file to appear in a folder.
|
|
@@ -31,3 +33,15 @@ def wait_for_download(folder: str, file_name: str | None, file_extension: str, t
|
|
|
31
33
|
time.sleep(1)
|
|
32
34
|
|
|
33
35
|
raise TimeoutError(f"Downloaded file didn't appear within {timeout} seconds.")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def handle_save_dialog(file_path: str):
|
|
39
|
+
"""Save a file using the default Windows file dialog.
|
|
40
|
+
The dialog is assumed to already be open.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
file_path: The absolute path to save the file at.
|
|
44
|
+
"""
|
|
45
|
+
file_dialog = uiautomation.WindowControl(Name="Gem som", searchDepth=2)
|
|
46
|
+
file_dialog.PaneControl(AutomationId="BackgroundClear", searchDepth=4).EditControl(AutomationId="1001").GetValuePattern().SetValue(file_path)
|
|
47
|
+
file_dialog.ButtonControl(Name="Gem", searchDepth=1).GetInvokePattern().Invoke()
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: itk_dev_shared_components
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.5.0
|
|
4
4
|
Summary: Shared components to use in RPA projects
|
|
5
5
|
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
6
|
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
@@ -15,6 +15,8 @@ Requires-Dist: pywin32>=306
|
|
|
15
15
|
Requires-Dist: msal>=1.24.1
|
|
16
16
|
Requires-Dist: requests>=2.31.0
|
|
17
17
|
Requires-Dist: beautifulsoup4>=4.12.2
|
|
18
|
+
Requires-Dist: selenium==4.16.0
|
|
19
|
+
Requires-Dist: uiautomation==2.0.18
|
|
18
20
|
Provides-Extra: dev
|
|
19
21
|
Requires-Dist: python-dotenv; extra == "dev"
|
|
20
22
|
Requires-Dist: flake8; extra == "dev"
|
|
@@ -7,6 +7,11 @@ itk_dev_shared_components.egg-info/SOURCES.txt
|
|
|
7
7
|
itk_dev_shared_components.egg-info/dependency_links.txt
|
|
8
8
|
itk_dev_shared_components.egg-info/requires.txt
|
|
9
9
|
itk_dev_shared_components.egg-info/top_level.txt
|
|
10
|
+
itk_dev_shared_components/eflyt/__init__.py
|
|
11
|
+
itk_dev_shared_components/eflyt/eflyt_case.py
|
|
12
|
+
itk_dev_shared_components/eflyt/eflyt_login.py
|
|
13
|
+
itk_dev_shared_components/eflyt/eflyt_search.py
|
|
14
|
+
itk_dev_shared_components/eflyt/eflyt_util.py
|
|
10
15
|
itk_dev_shared_components/graph/__init__.py
|
|
11
16
|
itk_dev_shared_components/graph/authentication.py
|
|
12
17
|
itk_dev_shared_components/graph/common.py
|
|
@@ -23,7 +28,9 @@ itk_dev_shared_components/kmd_nova/nova_objects.py
|
|
|
23
28
|
itk_dev_shared_components/kmd_nova/nova_tasks.py
|
|
24
29
|
itk_dev_shared_components/kmd_nova/util.py
|
|
25
30
|
itk_dev_shared_components/misc/__init__.py
|
|
31
|
+
itk_dev_shared_components/misc/address_lookup.py
|
|
26
32
|
itk_dev_shared_components/misc/cpr_util.py
|
|
33
|
+
itk_dev_shared_components/misc/cvr_lookup.py
|
|
27
34
|
itk_dev_shared_components/misc/file_util.py
|
|
28
35
|
itk_dev_shared_components/sap/__init__.py
|
|
29
36
|
itk_dev_shared_components/sap/fmcacov.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "itk_dev_shared_components"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.5.0"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="ITK Development", email="itk-rpa@mkb.aarhus.dk" },
|
|
10
10
|
]
|
|
@@ -21,6 +21,8 @@ dependencies = [
|
|
|
21
21
|
"msal >= 1.24.1",
|
|
22
22
|
"requests >= 2.31.0",
|
|
23
23
|
"beautifulsoup4 >= 4.12.2",
|
|
24
|
+
"selenium==4.16.0",
|
|
25
|
+
"uiautomation == 2.0.18"
|
|
24
26
|
]
|
|
25
27
|
|
|
26
28
|
[project.urls]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|