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:
BIN
__pycache__/galdPl.cpython-312.pyc
Normal file
BIN
__pycache__/galdPl.cpython-312.pyc
Normal file
Binary file not shown.
13
main.py
13
main.py
@@ -17,11 +17,13 @@ def get_json_files_from_folder(folder):
|
||||
r.raise_for_status()
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
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", "")
|
||||
if href.endswith(".json"):
|
||||
file_path = href.split("/resources/")[-1]
|
||||
files.append(file_path)
|
||||
if href.startswith("/gald/galdistream/src/branch/main/resources/"):
|
||||
# Extrahujeme pouze název souboru
|
||||
file_name = href.split("/")[-1]
|
||||
files.append(file_name)
|
||||
return files
|
||||
|
||||
def update_json_db():
|
||||
@@ -30,7 +32,8 @@ def update_json_db():
|
||||
all_files = []
|
||||
for folder in folders:
|
||||
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:
|
||||
print(f"Chyba při získávání souborů ze složky {folder}: {e}")
|
||||
for file in all_files:
|
||||
|
||||
Reference in New Issue
Block a user