feature: update funkcí pro stahování dat

funkce fetch_set a download_heslare byly upraveny pro stahování dat nejen z OAI-PMH API, ale nově i z API digiarchivu (= osoby se nově nestahují z hesláře osob, ale z facetek digiarchivu, kde mají osoby přidělené "role" nálezce/vedoucí)
This commit is contained in:
2026-06-29 13:48:23 +02:00
parent 66532c108b
commit e84ee8e543
+37 -6
View File
@@ -103,13 +103,19 @@ def load_all_data():
return categorized_data return categorized_data
def fetch_set(internal_name, api_set, task=None): def fetch_set(base_url, internal_name, api_set, task=None):
dataset = [] dataset = []
params = { params_amcr = {
"verb": "ListRecords", "verb": "ListRecords",
"metadataPrefix": "oai_dc", "metadataPrefix": "oai_dc",
"set": api_set "set": api_set
} }
params_da = {
"entity": "samostatny_nalez" if internal_name == "nalezce" else "akce",
"rows": 0,
"noFacets": "false",
"onlyFacets": "true"
}
while True: while True:
# Check for cancellation at each iteration # Check for cancellation at each iteration
@@ -117,7 +123,8 @@ def fetch_set(internal_name, api_set, task=None):
return None return None
try: try:
response = requests.get(BASE_URL, params=params, timeout=30) if "digiarchiv" not in base_url:
response = requests.get(base_url, params=params_amcr, timeout=30)
response.raise_for_status() response.raise_for_status()
root = ET.fromstring(response.content) # nosec root = ET.fromstring(response.content) # nosec
@@ -179,7 +186,7 @@ def fetch_set(internal_name, api_set, task=None):
# Pagination # Pagination
token = root.find('.//oai:resumptionToken', NS) token = root.find('.//oai:resumptionToken', NS)
if token is not None and token.text: if token is not None and token.text:
params = { params_amcr = {
"verb": "ListRecords", "verb": "ListRecords",
"resumptionToken": token.text "resumptionToken": token.text
} }
@@ -187,6 +194,25 @@ def fetch_set(internal_name, api_set, task=None):
else: else:
break break
else:
response = requests.get(base_url, params=params_da, timeout=30)
response.raise_for_status()
data_json = response.json()
records = data_json['facet_counts']['facet_fields'][api_set]
for r in records:
nazev = r["name"]
dataset.append({
'Název': nazev,
'Kód': nazev,
'Kategorie': internal_name
})
break
except Exception as e: except Exception as e:
QgsMessageLog.logMessage( QgsMessageLog.logMessage(
f"Chyba u setu {api_set}: {e}", f"Chyba u setu {api_set}: {e}",
@@ -201,8 +227,13 @@ def download_heslare(task=None):
ensure_codelists_dir() ensure_codelists_dir()
all_data = [] all_data = []
total_sets = len(slovnicek) total_sets = len(slovnicek)
# index, (interni, api_nazev)
for index, (key, value) in enumerate(slovnicek.items()):
base_url = value[0]
interni = key
api_nazev = value[1]
for index, (interni, api_nazev) in enumerate(slovnicek.items()):
# Check if the user cancelled the task via the QGIS taskbar # Check if the user cancelled the task via the QGIS taskbar
if task and task.isCanceled(): if task and task.isCanceled():
return False return False
@@ -212,7 +243,7 @@ def download_heslare(task=None):
"AMČR", Qgis.Info) "AMČR", Qgis.Info)
# Pass the task correctly to the updated fetch function # Pass the task correctly to the updated fetch function
data = fetch_set(interni, api_nazev, task=task) data = fetch_set(base_url, interni, api_nazev, task=task)
if data is None: if data is None:
return False # Cancelled mid-download return False # Cancelled mid-download