Refactor JSON file retrieval logic to filter links by .json extension and extract only file names for improved clarity and efficiency.

This commit is contained in:
2025-07-29 16:56:19 +02:00
parent 1801ad52b0
commit 7a614fd824
2 changed files with 8 additions and 5 deletions

Binary file not shown.

13
main.py
View File

@@ -17,11 +17,13 @@ def get_json_files_from_folder(folder):
r.raise_for_status() r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser") soup = BeautifulSoup(r.text, "html.parser")
files = [] files = []
for a in soup.find_all("a", class_="ui basic label"): # Hledáme odkazy s .json v href
for a in soup.find_all("a", href=lambda x: x and x.endswith('.json')):
href = a.get("href", "") href = a.get("href", "")
if href.endswith(".json"): if href.startswith("/gald/galdistream/src/branch/main/resources/"):
file_path = href.split("/resources/")[-1] # Extrahujeme pouze název souboru
files.append(file_path) file_name = href.split("/")[-1]
files.append(file_name)
return files return files
def update_json_db(): def update_json_db():
@@ -30,7 +32,8 @@ def update_json_db():
all_files = [] all_files = []
for folder in folders: for folder in folders:
try: try:
all_files += [f"{folder}/{file}" for file in get_json_files_from_folder(folder)] files = get_json_files_from_folder(folder)
all_files += [f"{folder}/{file}" for file in files]
except Exception as e: except Exception as e:
print(f"Chyba při získávání souborů ze složky {folder}: {e}") print(f"Chyba při získávání souborů ze složky {folder}: {e}")
for file in all_files: for file in all_files: