Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show images based on the envelopes feed parameter #81

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions custom_components/feedparser/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CONF_SHOW_TOPN = "show_topn"

DEFAULT_SCAN_INTERVAL = timedelta(hours=1)
DEFAULT_THUMBNAIL = "https://www.home-assistant.io/images/favicon-192x192-full.png"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
Expand Down Expand Up @@ -127,17 +128,22 @@ def update(self):
entry_value[key] = value

if "image" in self._inclusions and "image" not in entry_value.keys():
images = []
if "summary" in entry.keys():
images = re.findall(
r"<img.+?src=\"(.+?)\".+?>", entry["summary"]
)
if "enclosures" in entry:
images = [
enc
for enc in entry["enclosures"]
if enc.type.startswith("image/")
]
else:
images = []
if images:
entry_value["image"] = images[0]
entry_value["image"] = images[0][
"href"
] # pick the first image found
else:
entry_value[
"image"
] = "https://www.home-assistant.io/images/favicon-192x192-full.png"
] = DEFAULT_THUMBNAIL # use default image if no image found

self._entries.append(entry_value)

Expand Down
Loading