MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / random_anime_character

Function random_anime_character

web_programming/random_anime_character.py:29–43  ·  view source on GitHub ↗

Returns the Title, Description, and Image Title of a random anime character .

()

Source from the content-addressed store, hash-verified

27
28
29def random_anime_character() -> tuple[str, str, str]:
30 """
31 Returns the Title, Description, and Image Title of a random anime character .
32 """
33 soup = BeautifulSoup(
34 httpx.get(URL, headers=headers, timeout=10).text, "html.parser"
35 )
36 title = soup.find("meta", attrs={"property": "og:title"}).attrs["content"]
37 image_url = soup.find("meta", attrs={"property": "og:image"}).attrs["content"]
38 description = soup.find("p", id="description").get_text()
39 _, image_extension = os.path.splitext(os.path.basename(image_url))
40 image_title = title.strip().replace(" ", "_")
41 image_title = f"{image_title}{image_extension}"
42 save_image(image_url, image_title)
43 return (title, description, image_title)
44
45
46if __name__ == "__main__":

Callers 1

Calls 3

save_imageFunction · 0.85
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected