I went back to the original sensor.py file and changed the way it searches for the image.
The sensor.py file is found in â/config/custom_components/feedparserâ
The image extraction code starts at line 91:
if 'image' in self._inclusions and 'image' not in entryValue.keys():
images = []
if 'summary' in entry.keys():
images = re.findall(r"<img.+?src=\"(.+?)\".+?>", entry['summary'])
if images:
entryValue['image'] = images[0]
else:
entryValue['image'] = "https://www.home-assistant.io/images/favicon-192x192-full.png"
A better way to find the images is to use the keys, so I replaced the above code with the following:
if 'image' in self._inclusions and 'image' not in entryValue.keys():
images = []
if 'summary' in entry.keys():
images = re.findall(r"<img.+?src=\"(.+?)\".+?>", entry['summary'])
if images:
entryValue['image'] = images[0]
else:
if 'media_content' in entry.keys():
image = entry['media_content'][0]['url']
if image:
entryValue['image'] = image
else:
entryValue['image'] = "https://www.home-assistant.io/images/favicon-192x192-full.png"
The configuration.yaml is updated to :
- platform: feedparser
name: Engineering Feed
feed_url: 'https://www.is.fi/rss/tuoreimmat.xml'
inclusions:
- title
- link
- published
- summary
- image
After a restart the Development Tools : States for sensor.engineering_feed looks like:
entries:
- link: 'https://www.is.fi/tiede/art-2000007828573.html'
title: >-
Tutkijat: Kolmas annos koronaÂrokotetta voisi pĂ€ihittÀÀ uudet
virusÂmuunnokset
summary: >-
LÀÀkeyhtiöt suunnittelevat jo uuden polven rokotteita, mutta vanhoillakin
valmisteilla voitaisiin ehkÀ pÀrjÀtÀ uusia variantteja vastaan.
published: 'Fri, Feb 26 02:12 PM'
image: 'https://is.mediadelivery.fi/img/468/56a789fe58014e00b50aa1f9e6380026.jpg'
- link: 'https://www.is.fi/ruokala/ajankohtaista/art-2000007828571.html'
title: >-
Parempi kuin nachopelti! âMielettömĂ€ssĂ€ lohturuoassaâ on helppo kastike,
joka on kaupan purkkia parempaa
summary: >-
Sanna MansikkamÀen herkkupellissÀ juustokastike tehdÀÀn sekoittamalla
kahta eri vegejuustoa ja nachot korvataan perunalla.
published: 'Fri, Feb 26 02:12 PM'
image: 'https://is.mediadelivery.fi/img/468/932c58cc657d408783e6f12f8bd25943.jpg'
Hey, since this website will shutdown at 15.3.2021 do you have searched or/and found an alternative to this RSS feed yet?
i noticed today, that your cool workaround isnât working anymore=( and while we all are staying home, this has become a really important part of my configuration=)
I also noticed this today. Sad. I removed my pages and feedparaer and listcard with Netflix and prime feeds maybe I search for a replacement in the future. Havenât found a suitable solution yet.
I figured out my own issue, but I donât know how to fix it. As detailed here, base64.decodestring was already deprecated and was removed in Python 3.9. Thus- donât update to Python 3.9 until this gets fixed or youâll lose Feedparser.
Hi, Since some days ago my feedparser has stoped working and I get below error printout from HA.
It seams that the feedparser is recently updated, do I have to update something or is this a bug?
Thanks for any help
Matz
Iâve installed the feedparser component using HACS in my Home Assistant (latest version running in a Docker Container) and added the sample configuration into my configuration.yaml, and when I âcheck configurationâ I get this error:
Platform error sensor.feedparser - cannot import name 'SensorEntity' from 'homeassistant.helpers.entity' (/usr/src/homeassistant/homeassistant/helpers/entity.py)
Hi @smithbill17, you seams to have the same problem as I have, please look att @iantrich answer above.
The only thing now with @iantrich answer is that I have upgraded to 2021.4 but it didnât help so i hope there will be a fix.
Thanks @Matz. The suggestion from @iantrich is to either downgrade the component or upgrade HA, but Iâm already on HA v2021.4.0 (running successfully in a Docker Container). The custom component is installed okay, I only get the error when adding the sample to configuration.yaml.
I upgraded to feedparser v0.1.5 via HACS and with my v2021.4.0 HA, everything is now working. I just need to figure out how to use it properly Thanks @Matz for the pointer & to @iantrich for a great custom component.
Installed feedparser custom component v0.1.5 via HACS
Installed list-card as a custom repo via HACS
Added the sample code to my configuration.yaml and restarted HA okay
Checked in Developer > States > sensor.engineering_feed and itâs full of RSS articles each with fields title, link and image
I go to one of my Dashboards and add a Custom Card. In the code editor, I paste in the sample code, and I âsimplifiedâ it for testing to be:
type: 'custom:list-card'
entity: sensor.engineering_feed
title: Engineering
columns:
- title: Title
field: title
I saved the Custom Card and all I get on my Dashboard is a Custom Card that has title âEngineeringâ and column title âTitleâ and absolutely no articles listed. Why are they not being pulled from the sensor? What am I missing?
I havenât messed around with uilovelace.yaml or sensor.py or any other bits of code - I assume I donât have to do that if Iâve used HACS to install the two components and used the Custom Card code editor?
Apologies in advance for asking a dumb Newbie question.
Thank you! I thought I had tried that already and saw no difference, but Iâve just tried it again and itâs working now. I mustâve screwed it up when I tried it before. Thanks for the help.
Actually Iâve now found that my problem seems to be:
- title: Description
field: description
Whenever I include this field in the custom card, it fails to populate with any RSS articles. If I remove that title/field, then it works (the field is correctly defined in my configuration.yaml as shown in the example code).
Iâm also only getting the Home Assistant logo as the article images, but Iâm aware others have mentioned this in their posts - so Iâll read those messages more carefully to figure out that problem.
Am I correct in thinking this custom component is just not pulling all of the designated âincludedâ fields from the RSS feed?
Iâve tried multiple feeds and added/removed the âinclusionsâ to no avail. When I use Developer Tools > States > sensor.engineering_feed hereâs what I see:
entries:
- title: >-
Where will Prince Philip's body be held and moved to before he is laid to
rest?
link: >-
https://www.mirror.co.uk/news/uk-news/prince-philip-dukes-body-held-23886320
image: 'https://www.home-assistant.io/images/favicon-192x192-full.png'
- title: >-
TV schedule change explained as Emmerdale, Corrie and EastEnders not on
tonight
link: >-
https://www.mirror.co.uk/tv/tv-news/emmerdale-coronation-street-eastenders-not-23886423
image: 'https://www.home-assistant.io/images/favicon-192x192-full.png'
- title: >-
Travelodge currently has family rooms in Cornwall from ÂŁ20.75pp for the
summer
link: >-
https://www.mirror.co.uk/travel/uk-ireland/travelodge-rooms-cornwall-20pp-july-23879194
image: 'https://www.home-assistant.io/images/favicon-192x192-full.png'
The âimageâ is always the HomeAssistant logo and the only fields pulled from the RSS are title, link and the home assistant image.
Does this custom component no longer work??
UPDATE:
Okay, I think Iâve understood my problem: if your configuration.yaml includes any âinclusionâ fields which donât exist in the RSS feed, then it simply fails to pull back any of the subsequent fields into the sensor.
So now my configuration.yaml looks like this and pulls everything back:
im stucking at an related point, I got feed parser 0.1.5 installed on HassIO 2021.4.4 and I canât get all info from my feed.
If I set title and summary I get my feed accordingly buuut I wanted to explore a bit further so added
anyone an idea how to fix this? if I download the xml directly I can see some fields but they donât get picked up (for instance: there is a field âdescriptionsâ which doesnât work, but with âsummaryâ I get the information provided in this field)⊠so im totally lost, thought I got a bit deeper to it but nope