Returns the Title, Description, and Image Title of a random anime character .
()
| 27 | |
| 28 | |
| 29 | def 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 | |
| 46 | if __name__ == "__main__": |
no test coverage detected