Compare commits

...
Author SHA1 Message Date
david-spacil 2fdbb15001 feature: aktualizace hesláře 2026-06-29 13:50:53 +02:00
david-spacil 8248d1bcae feature: nové heslářové globals + cache v dialogu 2026-06-29 13:50:39 +02:00
david-spacil abb06b9858 feature: globals pro PAS
založeny nové heslářové globals, pak přidány do funkce refresh_globals
2026-06-29 13:49:12 +02:00
david-spacil e84ee8e543 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í)
2026-06-29 13:48:23 +02:00
david-spacil 66532c108b feature: rozšíření slovníčku
slovníček interních vs api klíčů byl rozšířen o nová pole (nálezce, okolnosti, ...) a zároveň byla změněna jeho struktura: nově obsahuje i base url vzhledem k tomu, že si skript pro data sahá do dvou různých API; přidáno base url pro digiarchiv
2026-06-29 13:44:54 +02:00
david-spacil 86da8b9cf4 feature: tlačítko v menu
v kontextové nabídce přibylo tlačítko pro filtrování PASových záznamů; ikona je zatím placeholder
2026-06-29 13:41:44 +02:00
david-spacil a95831f180 feature: dialog: přidána nová pole
přidána pole samostatných nálezů pro filtrovací dialog + upravena viditelnost některých spolčných polí (např. skrýt areál, zobrazit organizaci nejen pro akce, ale i pro PAS, ...)
2026-06-29 13:39:44 +02:00
4 changed files with 17054 additions and 21982 deletions

No files matched your search

+136 -84
View File
@@ -9,24 +9,30 @@ from qgis.core import QgsMessageLog, Qgis
# Define paths for the plugin and its codelists directory # Define paths for the plugin and its codelists directory
PLUGIN_DIR = os.path.dirname(__file__) PLUGIN_DIR = os.path.dirname(__file__)
CODELISTS_DIR = os.path.join(PLUGIN_DIR, 'codelists') CODELISTS_DIR = os.path.join(PLUGIN_DIR, 'codelists')
BASE_URL = "https://api.aiscr.cz/2.2/oai" BASE_URL_AMCR = "https://api.aiscr.cz/2.2/oai"
BASE_URL_DA = "https://digiarchiv.aiscr.cz/api/search/query"
OUTPUT_FILE = os.path.join(CODELISTS_DIR, 'heslar.csv') OUTPUT_FILE = os.path.join(CODELISTS_DIR, 'heslar.csv')
slovnicek = { slovnicek = {
'obdobi': 'heslo:obdobi', 'obdobi': (BASE_URL_AMCR, 'heslo:obdobi'),
'typ_akce': 'heslo:akce_typ', 'typ_akce': (BASE_URL_AMCR, 'heslo:akce_typ'),
'areal': 'heslo:areal', 'areal': (BASE_URL_AMCR, 'heslo:areal'),
'kraj': 'ruian_kraj', 'kraj': (BASE_URL_AMCR, 'ruian_kraj'),
'organizace': 'organizace', 'organizace': (BASE_URL_AMCR, 'organizace'),
'okres': 'ruian_okres', 'okres': (BASE_URL_AMCR, 'ruian_okres'),
'katastr': 'ruian_katastr', 'katastr': (BASE_URL_AMCR, 'ruian_katastr'),
'vedouci': 'osoba', 'pian_presnost': (BASE_URL_AMCR, 'heslo:pian_presnost'),
'pian_presnost': 'heslo:pian_presnost', 'typ_lokality': (BASE_URL_AMCR, 'heslo:lokalita_typ'),
'typ_lokality': 'heslo:lokalita_typ', 'druh_lokality': (BASE_URL_AMCR, 'heslo:lokalita_druh'),
'druh_lokality': 'heslo:lokalita_druh', 'jistota': (BASE_URL_AMCR, 'heslo:jistota_urceni'),
'jistota': 'heslo:jistota_urceni', 'lokalita_zachovalost': (BASE_URL_AMCR, 'heslo:stav_dochovani'),
'lokalita_zachovalost': 'heslo:stav_dochovani', 'pristupnost': (BASE_URL_AMCR, 'heslo:pristupnost'),
'pristupnost': 'heslo:pristupnost' 'nalez_kategorie': (BASE_URL_AMCR, 'heslo:predmet_druh_kat'),
'druh_nalezu': (BASE_URL_AMCR, 'heslo:predmet_druh'),
'specifikace': (BASE_URL_AMCR, 'heslo:predmet_specifikace'),
'nalezove_okolnosti': (BASE_URL_AMCR, 'heslo:nalezove_okolnosti'),
'vedouci': (BASE_URL_DA, 'f_vedouci'),
'nalezce': (BASE_URL_DA, 'f_nalezce'),
} }
NS = { NS = {
@@ -97,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
@@ -111,75 +123,95 @@ 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.raise_for_status() response = requests.get(base_url, params=params_amcr, timeout=30)
root = ET.fromstring(response.content) # nosec response.raise_for_status()
root = ET.fromstring(response.content) # nosec
records = root.findall('.//oai:record', NS) records = root.findall('.//oai:record', NS)
for rec in records: for rec in records:
metadata = rec.find('.//oai_dc:dc', NS) metadata = rec.find('.//oai_dc:dc', NS)
if metadata is not None: if metadata is not None:
# Code (identifier) # Code (identifier)
identifier_el = metadata.find('dc:identifier', NS) identifier_el = metadata.find('dc:identifier', NS)
kod = ( kod = (
identifier_el.text identifier_el.text
if identifier_el is not None if identifier_el is not None
else "" else ""
)
# Title – filter out system labels "AMČR - ..."
titles = metadata.findall('dc:title', NS)
nazev = ""
for t in titles:
if (
t.text
and not t.text.startswith("AMČR -")
and not t.text.startswith(" AMČR -")
):
nazev = t.text
break
# If no title passed the filter, fall back
# to the first available one
if not nazev and titles:
nazev = titles[0].text
specialni_pripady = ['okres', 'katastr']
if internal_name in specialni_pripady:
kod = nazev
if internal_name == 'pristupnost':
kod = next(
(
t.text for t in titles
if t.text
and len(t.text) == 1
and t.text.isalpha()
),
None
) )
# Skip records without a valid one-letter code –
# a None code would end up in the CSV and later # Title – filter out system labels "AMČR - ..."
# in the API filter as the string "None" titles = metadata.findall('dc:title', NS)
if not kod: nazev = ""
continue for t in titles:
if (
t.text
and not t.text.startswith("AMČR -")
and not t.text.startswith(" AMČR -")
):
nazev = t.text
break
# If no title passed the filter, fall back
# to the first available one
if not nazev and titles:
nazev = titles[0].text
specialni_pripady = ['okres', 'katastr']
if internal_name in specialni_pripady:
kod = nazev
if internal_name == 'pristupnost':
kod = next(
(
t.text for t in titles
if t.text
and len(t.text) == 1
and t.text.isalpha()
),
None
)
# Skip records without a valid one-letter code –
# a None code would end up in the CSV and later
# in the API filter as the string "None"
if not kod:
continue
dataset.append({
'Název': nazev,
'Kód': kod,
'Kategorie': internal_name
})
# Pagination
token = root.find('.//oai:resumptionToken', NS)
if token is not None and token.text:
params_amcr = {
"verb": "ListRecords",
"resumptionToken": token.text
}
time.sleep(0.5)
else:
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({ dataset.append({
'Název': nazev, 'Název': nazev,
'Kód': kod, 'Kód': nazev,
'Kategorie': internal_name 'Kategorie': internal_name
}) })
# Pagination break
token = root.find('.//oai:resumptionToken', NS)
if token is not None and token.text:
params = {
"verb": "ListRecords",
"resumptionToken": token.text
}
time.sleep(0.5)
else:
break
except Exception as e: except Exception as e:
QgsMessageLog.logMessage( QgsMessageLog.logMessage(
@@ -195,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
@@ -206,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
@@ -260,6 +297,16 @@ def refresh_globals():
LOKALITA_ZACHOVALOST.update(data.get('lokalita_zachovalost', {})) LOKALITA_ZACHOVALOST.update(data.get('lokalita_zachovalost', {}))
PRISTUPNOST.clear() PRISTUPNOST.clear()
PRISTUPNOST.update(data.get('pristupnost', {})) PRISTUPNOST.update(data.get('pristupnost', {}))
NALEZ_KATEGORIE.clear()
NALEZ_KATEGORIE.update(data.get('nalez_kategorie', {}))
DRUH_NALEZU.clear()
DRUH_NALEZU.update(data.get('druh_nalezu', {}))
SPECIFIKACE.clear()
SPECIFIKACE.update(data.get('specifikace', {}))
NALEZOVE_OKOLNOSTI.clear()
NALEZOVE_OKOLNOSTI.update(data.get('nalezove_okolnosti', {}))
NALEZCE.clear()
NALEZCE.update(data.get('nalezce', {}))
# Initialize empty dicts that will be populated immediately below # Initialize empty dicts that will be populated immediately below
@@ -277,5 +324,10 @@ DRUH_LOKALITY = {}
JISTOTA = {} JISTOTA = {}
LOKALITA_ZACHOVALOST = {} LOKALITA_ZACHOVALOST = {}
PRISTUPNOST = {} PRISTUPNOST = {}
NALEZ_KATEGORIE = {}
DRUH_NALEZU = {}
SPECIFIKACE = {}
NALEZOVE_OKOLNOSTI = {}
NALEZCE = {}
refresh_globals() refresh_globals()
+72 -25
View File
@@ -11,7 +11,9 @@ from qgis.utils import iface
from .amcr_codelists import (OBDOBI, TYP_AKCE, KRAJE, AREAL, ORGANIZACE, from .amcr_codelists import (OBDOBI, TYP_AKCE, KRAJE, AREAL, ORGANIZACE,
OKRESY, KATASTRY, VEDOUCI, PIAN_PRESNOST, OKRESY, KATASTRY, VEDOUCI, PIAN_PRESNOST,
TYP_LOKALITY, DRUH_LOKALITY, JISTOTA, TYP_LOKALITY, DRUH_LOKALITY, JISTOTA,
LOKALITA_ZACHOVALOST, PRISTUPNOST, LOKALITA_ZACHOVALOST, PRISTUPNOST,
NALEZ_KATEGORIE, DRUH_NALEZU, SPECIFIKACE,
NALEZOVE_OKOLNOSTI, NALEZCE,
download_heslare, refresh_globals) download_heslare, refresh_globals)
@@ -168,6 +170,11 @@ class AmcrFilterDialog(QDialog):
'druh_lokality': [], 'druh_lokality': [],
'jistota': [], 'jistota': [],
'lokalita_zachovalost': [], 'lokalita_zachovalost': [],
'nalez_kategorie': [],
'druh_nalezu': [],
'specifikace': [],
'nalezove_okolnosti': [],
'nalezce': [],
} }
layout = QVBoxLayout() layout = QVBoxLayout()
@@ -218,7 +225,7 @@ class AmcrFilterDialog(QDialog):
# Filters valid for Akce # Filters valid for Akce
if self.typ_dat == "akce": if self.typ_dat in ["pas", "akce"]:
self.picker_org = self.setup_picker( self.picker_org = self.setup_picker(
"Organizace", "Organizace",
'organizace', 'organizace',
@@ -226,6 +233,7 @@ class AmcrFilterDialog(QDialog):
) )
layout.addWidget(self.picker_org) layout.addWidget(self.picker_org)
if self.typ_dat == "akce":
self.picker_vedouci = self.setup_picker( self.picker_vedouci = self.setup_picker(
"Vedoucí výzkumu", "Vedoucí výzkumu",
'vedouci', 'vedouci',
@@ -278,12 +286,49 @@ class AmcrFilterDialog(QDialog):
self.picker_obdobi = self.setup_picker("Období", 'obdobi', OBDOBI) self.picker_obdobi = self.setup_picker("Období", 'obdobi', OBDOBI)
layout.addWidget(self.picker_obdobi) layout.addWidget(self.picker_obdobi)
self.picker_areal = self.setup_picker("Areál", 'areal', AREAL) if self.typ_dat == "pas":
layout.addWidget(self.picker_areal) self.picker_nalez_kategorie = self.setup_picker(
"Kategorie nálezu",
'nalez_kategorie',
NALEZ_KATEGORIE
)
layout.addWidget(self.picker_nalez_kategorie)
# Option to download related components table self.picker_druh_nalezu = self.setup_picker(
self.chk_komponenty = QCheckBox("Načíst komponenty") "Druh nálezu",
layout.addWidget(self.chk_komponenty) 'druh_nalezu',
DRUH_NALEZU
)
layout.addWidget(self.picker_druh_nalezu)
self.picker_specifikace = self.setup_picker(
"Specifikace nálezu",
'specifikace',
SPECIFIKACE
)
layout.addWidget(self.picker_specifikace)
self.picker_nalezove_okolnosti = self.setup_picker(
"Okolnosti nálezu",
'nalezove_okolnosti',
NALEZOVE_OKOLNOSTI
)
layout.addWidget(self.picker_nalezove_okolnosti)
self.picker_nalezce = self.setup_picker(
"Nálezce",
'nalezce',
NALEZCE
)
layout.addWidget(self.picker_nalezce)
if self.typ_dat != "pas":
self.picker_areal = self.setup_picker("Areál", 'areal', AREAL)
layout.addWidget(self.picker_areal)
# Option to download related components table
self.chk_komponenty = QCheckBox("Načíst komponenty")
layout.addWidget(self.chk_komponenty)
# Warning label # Warning label
self.lbl_komponenty_warning = QLabel( self.lbl_komponenty_warning = QLabel(
@@ -299,9 +344,10 @@ class AmcrFilterDialog(QDialog):
self.lbl_komponenty_warning.setVisible(False) self.lbl_komponenty_warning.setVisible(False)
layout.addWidget(self.lbl_komponenty_warning) layout.addWidget(self.lbl_komponenty_warning)
self.chk_komponenty.toggled.connect( if self.typ_dat != "pas":
self.lbl_komponenty_warning.setVisible self.chk_komponenty.toggled.connect(
) self.lbl_komponenty_warning.setVisible
)
# Pushes everything above to the top # Pushes everything above to the top
layout.addStretch(1) layout.addStretch(1)
@@ -470,22 +516,23 @@ class AmcrFilterDialog(QDialog):
filters['posevidence'] = 'true' filters['posevidence'] = 'true'
if self.chk_proj_akce.isChecked(): if self.chk_proj_akce.isChecked():
filters['proj_akce'] = 'true' filters['proj_akce'] = 'true'
if self.selection_cache['organizace']:
filters['f_organizace'] = self.selection_cache['organizace']
if self.selection_cache['typ_akce']:
filters['f_typ_vyzkumu'] = self.selection_cache['typ_akce']
if self.selection_cache['vedouci']:
filters['f_vedouci'] = self.selection_cache['vedouci']
if self.typ_dat == "lokalita": if self.selection_cache['typ_akce']:
if self.selection_cache['typ_lokality']: filters['f_typ_vyzkumu'] = self.selection_cache['typ_akce']
filters['f_typ_lokality'] = self.selection_cache['typ_lokality'] if self.selection_cache['vedouci']:
if self.selection_cache['druh_lokality']: filters['f_vedouci'] = self.selection_cache['vedouci']
filters['f_druh_lokality'] = self.selection_cache['druh_lokality']
if self.selection_cache['jistota']: if self.selection_cache['organizace']:
filters['f_jistota'] = self.selection_cache['jistota'] filters['f_organizace'] = self.selection_cache['organizace']
if self.selection_cache['lokalita_zachovalost']:
filters['f_lokalita_zachovalost'] = self.selection_cache['lokalita_zachovalost'] if self.selection_cache['typ_lokality']:
filters['f_typ_lokality'] = self.selection_cache['typ_lokality']
if self.selection_cache['druh_lokality']:
filters['f_druh_lokality'] = self.selection_cache['druh_lokality']
if self.selection_cache['jistota']:
filters['f_jistota'] = self.selection_cache['jistota']
if self.selection_cache['lokalita_zachovalost']:
filters['f_lokalita_zachovalost'] = self.selection_cache['lokalita_zachovalost']
return filters return filters
+11
View File
@@ -90,6 +90,7 @@ class AmcrViewer:
""" """
# Define paths for action-specific icons # Define paths for action-specific icons
icon_akce_path = os.path.join(self.plugin_dir, 'akce.png') icon_akce_path = os.path.join(self.plugin_dir, 'akce.png')
icon_pas_path = os.path.join(self.plugin_dir, 'akce.png')
icon_lokality_path = os.path.join(self.plugin_dir, 'lokality.png') icon_lokality_path = os.path.join(self.plugin_dir, 'lokality.png')
icon_amcr_help_path = os.path.join(self.plugin_dir, 'amcr-help.png') icon_amcr_help_path = os.path.join(self.plugin_dir, 'amcr-help.png')
@@ -109,6 +110,16 @@ class AmcrViewer:
) )
self.plugin_menu.addAction(self.action_download_akce) self.plugin_menu.addAction(self.action_download_akce)
self.action_download_pas = self.add_action(
icon_path=icon_pas_path,
text=self.tr(u'Stáhnout data samostatných nálezů | AMČR Viewer'),
callback=lambda checked=False: self.run_download('pas'),
parent=self.iface.mainWindow(),
add_to_menu=False,
add_to_toolbar=False
)
self.plugin_menu.addAction(self.action_download_pas)
self.action_download_lokality = self.add_action( self.action_download_lokality = self.add_action(
icon_path=icon_lokality_path, icon_path=icon_lokality_path,
text=self.tr(u'Stáhnout data lokalit | AMČR Viewer'), text=self.tr(u'Stáhnout data lokalit | AMČR Viewer'),
+16835 -21873
View File
File diff suppressed because it is too large. Load diff