mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Save identically named files under different names
This commit is contained in:
parent
98a2b5db34
commit
dad33b8c7f
@ -76,6 +76,7 @@ class ILIAS:
|
|||||||
|
|
||||||
def _find_files(self, soup):
|
def _find_files(self, soup):
|
||||||
files = []
|
files = []
|
||||||
|
file_names = set()
|
||||||
|
|
||||||
found = soup.find_all("a", {"class": "il_ContainerItemTitle", "href": self.FILE_RE})
|
found = soup.find_all("a", {"class": "il_ContainerItemTitle", "href": self.FILE_RE})
|
||||||
for element in found:
|
for element in found:
|
||||||
@ -84,7 +85,17 @@ class ILIAS:
|
|||||||
file_id = re.search(self.FILE_RE, element.get("href")).group(1)
|
file_id = re.search(self.FILE_RE, element.get("href")).group(1)
|
||||||
|
|
||||||
file_name = f"{file_stem}.{file_type}"
|
file_name = f"{file_stem}.{file_type}"
|
||||||
|
if file_name in file_names:
|
||||||
|
counter = 1
|
||||||
|
while True:
|
||||||
|
file_name = f"{file_stem} (duplicate {counter}).{file_type}"
|
||||||
|
if file_name in file_names:
|
||||||
|
counter += 1
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
files.append((file_name, file_id))
|
files.append((file_name, file_id))
|
||||||
|
file_names.add(file_name)
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user