aboutsummaryrefslogtreecommitdiff
path: root/core/image.py
diff options
context:
space:
mode:
authorGravatar Anshul Gupta <ansg191@anshulg.com> 2024-11-15 14:13:32 -0800
committerGravatar Anshul Gupta <ansg191@anshulg.com> 2024-11-15 14:20:23 -0800
commita9409f08bac76b041fda8675858290d915a183aa (patch)
treea9c6b1f9430351b85f9c2400cd765e848638c8af /core/image.py
parentcd2f847c940a5cf110d138a48d66d1140b76c4f8 (diff)
downloadminiflux-ai-a9409f08bac76b041fda8675858290d915a183aa.tar.gz
miniflux-ai-a9409f08bac76b041fda8675858290d915a183aa.tar.zst
miniflux-ai-a9409f08bac76b041fda8675858290d915a183aa.zip
Add image processing and extra data to openai call
Diffstat (limited to 'core/image.py')
-rw-r--r--core/image.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/image.py b/core/image.py
new file mode 100644
index 0000000..7e3c68d
--- /dev/null
+++ b/core/image.py
@@ -0,0 +1,23 @@
+from bs4 import BeautifulSoup
+from typing import Optional
+
+
+def contains_image(html: str) -> Optional[str]:
+ """
+ Extracts the source URL of the first image found in the given HTML content.
+
+ This function parses the provided HTML string to locate the first image
+ (`<img>`) tag. If an image tag is found, it returns the value of the `src`
+ attribute. If no image is found, it returns None.
+
+ :param html: A string containing HTML content to be parsed.
+ :type html: str
+ :return: The `src` attribute value of the first found image tag, or None if
+ no image tag is found.
+ :rtype: Optional[str]
+ """
+ soup = BeautifulSoup(html, "html.parser")
+ image = soup.find("img", recursive=True)
+ if image:
+ return image.get("src")
+ return None