custom-components / feedparser

📰 RSS Feed Integration
MIT License
145 stars 32 forks source link

Filtering #61

Open nTx-Cheerok opened 2 years ago

nTx-Cheerok commented 2 years ago

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.

macross5 commented 1 year ago

i would love it aswell

macross5 commented 1 year ago

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

Vitani commented 1 year ago

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.

macross5 commented 1 year ago

I scripted the last hours and got this to work:

` template:

nTx-Cheerok commented 1 year ago

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.

ogajduse commented 1 year ago

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

Vitani commented 1 year ago

@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>webteam@metoffice.gov.uk</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