feedparser icon indicating copy to clipboard operation
feedparser copied to clipboard

Filtering

Open nTx-Cheerok opened this issue 2 years ago • 7 comments

Hi im using this component for some time now and it generellay works great with the custom lovelace card. However i was wondering if i could filter the entries of a feed efficiently without the need to fiddle around with template sensors. Like only show titles that include a certain string or something like that. The reason i ask is that i kind of get it working with templates but not optimally.

nTx-Cheerok avatar Apr 05 '22 17:04 nTx-Cheerok

i would love it aswell

macross5 avatar Apr 04 '23 09:04 macross5

@nTx-Cheerok can you show me an example for the templating?

macross5 avatar Apr 04 '23 09:04 macross5

Me too, I use an RSS feed for weather alerts; the feed covers an entire region, but lists the cities affected in the "locations" field of each alert; it'd be nice to stick a regex on that field to only show alerts which affect my city.

Vitani avatar Apr 04 '23 09:04 Vitani

I scripted the last hours and got this to work:

` template:

  • sensor:
    • name: "(TEST) RSS" state: "{{ states('sensor.rss_feed') | int }}" attributes: entries: >- {% set rss_list = namespace(entries=[]) %} {% for entries in state_attr('sensor.rss_feed','entries') -%} {% if "filter1" in entries['title']|lower or "filter2" in entries['title']|lower or "filter3" in entries['title']|lower -%} {% set rss_list.entries = rss_list.entries + [entries] %} {% endif -%} {% endfor %} {{ rss_list.entries }} `

macross5 avatar Apr 04 '23 15:04 macross5

Hi peops, i was very busy and this also kind of an old post :D I switched setups and erased some stuff, including the stuff i needed the feed parser for. Ill see if i can find my old backups as the config must still be in there and post my example.

nTx-Cheerok avatar Apr 05 '23 08:04 nTx-Cheerok

@Vitani Could you post the URLof the RSS feed that you use for weather alerts here?

ogajduse avatar Jul 27 '23 08:07 ogajduse

@ogajduse this is the specific one I use - http://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/em, but there are more of them - https://www.metoffice.gov.uk/weather/guides/rss

Not sure how useful they will be right now, as there are currently no weather warnings in place for the UK

Edit: There are rain & thunderstorm warnings today, here's the feed -

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Met Office warnings for East Midlands</title>
        <link>https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings</link>
        <description>Weather warnings of severe and extreme weather from the Met Office</description>
        <language>en-gb</language>
        <copyright>(c) Crown copyright</copyright>
        <pubDate>Wed, 02 Aug 2023 08:32:41 GMT</pubDate>
        <dc:creator>[email protected]</dc:creator>
        <item>
            <title>Yellow warning of thunderstorm affecting East Midlands</title>
            <link>https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2023-08-02&amp;id=da1b66c8-0df8-49f0-a6a5-7f255d0cb8a9&amp;referrer=rss</link>
            <description>Yellow warning of thunderstorm affecting East Midlands: Derby, Derbyshire, Leicester, Leicestershire, Lincolnshire, Northamptonshire, Nottingham, Nottinghamshire, Rutland valid from 0800 Wed 02 Aug to 1900 Wed 02 Aug</description>
            <guid isPermaLink="false">https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2023-08-02&amp;id=da1b66c8-0df8-49f0-a6a5-7f255d0cb8a9&amp;referrer=rss&amp;region=East Midlands</guid>
            <enclosure length="109337" type="image/png" url="https://cdn.prod.weathercloud.metoffice.gov.uk/warnings/rss/image/yellow-thunderstorm.png"/>
        </item>
        <item>
            <title>Yellow warning of rain affecting East Midlands</title>
            <link>https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2023-08-02&amp;id=2be5c1e8-2717-45ac-a32e-581b313e9943&amp;referrer=rss</link>
            <description>Yellow warning of rain affecting East Midlands: Lincolnshire, Nottinghamshire valid from 1000 Wed 02 Aug to 1900 Wed 02 Aug</description>
            <guid isPermaLink="false">https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2023-08-02&amp;id=2be5c1e8-2717-45ac-a32e-581b313e9943&amp;referrer=rss&amp;region=East Midlands</guid>
            <enclosure length="98657" type="image/png" url="https://cdn.prod.weathercloud.metoffice.gov.uk/warnings/rss/image/yellow-rain.png"/>
        </item>
    </channel>
</rss>

I would like to filter these items so that if the description contains "Leicester" then it is shown (so in the example above I would only see the "Yellow warning of thunderstorm" item

Vitani avatar Jul 27 '23 09:07 Vitani