mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Crawl ilias booking objects as links
This commit is contained in:
parent
89be07d4d3
commit
8ec3f41251
@ -22,6 +22,7 @@ class IliasElementType(Enum):
|
|||||||
FOLDER = "folder"
|
FOLDER = "folder"
|
||||||
FORUM = "forum"
|
FORUM = "forum"
|
||||||
LINK = "link"
|
LINK = "link"
|
||||||
|
BOOKING = "booking"
|
||||||
MEETING = "meeting"
|
MEETING = "meeting"
|
||||||
VIDEO = "video"
|
VIDEO = "video"
|
||||||
VIDEO_PLAYER = "video_player"
|
VIDEO_PLAYER = "video_player"
|
||||||
@ -490,6 +491,9 @@ class IliasPage:
|
|||||||
if str(img_tag["src"]).endswith("icon_webr.svg"):
|
if str(img_tag["src"]).endswith("icon_webr.svg"):
|
||||||
return IliasElementType.LINK
|
return IliasElementType.LINK
|
||||||
|
|
||||||
|
if str(img_tag["src"]).endswith("icon_book.svg"):
|
||||||
|
return IliasElementType.BOOKING
|
||||||
|
|
||||||
if str(img_tag["src"]).endswith("frm.svg"):
|
if str(img_tag["src"]).endswith("frm.svg"):
|
||||||
return IliasElementType.FORUM
|
return IliasElementType.FORUM
|
||||||
|
|
||||||
|
@ -323,6 +323,8 @@ instance's greatest bottleneck.
|
|||||||
return None
|
return None
|
||||||
elif element.type == IliasElementType.LINK:
|
elif element.type == IliasElementType.LINK:
|
||||||
return await self._handle_link(element, element_path)
|
return await self._handle_link(element, element_path)
|
||||||
|
elif element.type == IliasElementType.BOOKING:
|
||||||
|
return await self._handle_booking(element, element_path)
|
||||||
elif element.type == IliasElementType.VIDEO:
|
elif element.type == IliasElementType.VIDEO:
|
||||||
return await self._handle_file(element, element_path)
|
return await self._handle_file(element, element_path)
|
||||||
elif element.type == IliasElementType.VIDEO_PLAYER:
|
elif element.type == IliasElementType.VIDEO_PLAYER:
|
||||||
@ -362,14 +364,56 @@ instance's greatest bottleneck.
|
|||||||
async with dl as (bar, sink):
|
async with dl as (bar, sink):
|
||||||
export_url = element.url.replace("cmd=calldirectlink", "cmd=exportHTML")
|
export_url = element.url.replace("cmd=calldirectlink", "cmd=exportHTML")
|
||||||
real_url = await self._resolve_link_target(export_url)
|
real_url = await self._resolve_link_target(export_url)
|
||||||
|
self._write_link_content(link_template, real_url, element.name, element.description, sink)
|
||||||
|
|
||||||
content = link_template
|
def _write_link_content(
|
||||||
content = content.replace("{{link}}", real_url)
|
self,
|
||||||
content = content.replace("{{name}}", element.name)
|
link_template: str,
|
||||||
content = content.replace("{{description}}", str(element.description))
|
url: str,
|
||||||
content = content.replace("{{redirect_delay}}", str(self._link_file_redirect_delay))
|
name: str,
|
||||||
sink.file.write(content.encode("utf-8"))
|
description: Optional[str],
|
||||||
sink.done()
|
sink: FileSink,
|
||||||
|
) -> None:
|
||||||
|
content = link_template
|
||||||
|
content = content.replace("{{link}}", url)
|
||||||
|
content = content.replace("{{name}}", name)
|
||||||
|
content = content.replace("{{description}}", str(description))
|
||||||
|
content = content.replace("{{redirect_delay}}", str(self._link_file_redirect_delay))
|
||||||
|
sink.file.write(content.encode("utf-8"))
|
||||||
|
sink.done()
|
||||||
|
|
||||||
|
async def _handle_booking(
|
||||||
|
self,
|
||||||
|
element: IliasPageElement,
|
||||||
|
element_path: PurePath,
|
||||||
|
) -> Optional[Awaitable[None]]:
|
||||||
|
log.explain_topic(f"Decision: Crawl Booking Link {fmt_path(element_path)}")
|
||||||
|
log.explain(f"Links type is {self._links}")
|
||||||
|
|
||||||
|
link_template_maybe = self._links.template()
|
||||||
|
link_extension = self._links.extension()
|
||||||
|
if not link_template_maybe or not link_extension:
|
||||||
|
log.explain("Answer: No")
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
log.explain("Answer: Yes")
|
||||||
|
element_path = element_path.with_name(element_path.name + link_extension)
|
||||||
|
|
||||||
|
maybe_dl = await self.download(element_path, mtime=element.mtime)
|
||||||
|
if not maybe_dl:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self._download_booking(element, link_template_maybe, maybe_dl)
|
||||||
|
|
||||||
|
@_iorepeat(3, "resolving booking")
|
||||||
|
async def _download_booking(
|
||||||
|
self,
|
||||||
|
element: IliasPageElement,
|
||||||
|
link_template: str,
|
||||||
|
dl: DownloadToken,
|
||||||
|
) -> None:
|
||||||
|
async with dl as (bar, sink):
|
||||||
|
self._write_link_content(link_template, element.url, element.name, element.description, sink)
|
||||||
|
|
||||||
async def _resolve_link_target(self, export_url: str) -> str:
|
async def _resolve_link_target(self, export_url: str) -> str:
|
||||||
async with self.session.get(export_url, allow_redirects=False) as resp:
|
async with self.session.get(export_url, allow_redirects=False) as resp:
|
||||||
|
Loading…
Reference in New Issue
Block a user