I am trying to set up a WebParser RSS feed reader following the various examples on this site but I've gotten stuck with one problem: variable feed number.
Specifically I'm trying to create a feed for the National Hurricane Center's Atlantic feed:
http://www.nhc.noaa.gov/index-at.xml
The problem is that the examples listed for RSS show the five most recent entries on a generic RSS feed. The NHC's hurricane feed has a variable number of entries. On days when there are no storms, there's only two (one announcing no cyclonic disturbances and the other announcing the Atlantic Tropical Weather Outlook). But when a storm pops up, several new items show up in the feed (Advisories, Forecasts, Projections, etc.).
Now, when I have the regex set to display five feeds as per the RSS examples (using StringIndex, etc.), Rainmeter bombs out when the list is too short. The log files show that something has happened and ends up with an index of -1 presumably because the twelve saved patterns (.*) in the regex don't exist (only two item tags instead of five). I verified this by shortening the regex to just four saved patterns and it works but obviously only provides the first two item entries (two saved patterns per entry, one for title and one for link).
Is there a way to display an RSS feed with a variable number of items such that it always works?
The original regex is:
RegExp="(?siU)<title>(.*)</title>.*<link>(.*)</link>.*<item>.*<title>(.*)</title>.*<link>(.*)</link>.*<item>.*<title>(.*)</title>.*<link>(.*)</link>.*<item>.*<title>(.*)</title>.*<link>(.*)</link>.*<item>.*<title>(.*)</title>.*<link>(.*)</link>.*<item>.*<title>(.*)</title>.*<link>(.*)</link>"
This does work when a storm is active and there are more than five items on the feed (there are typically twelve items per storm). But when things turn calm, the updates fail completely and I get a blank meter. Of course, this also doesn't work if there are two active storms because then there are at least 24 items but my regex only has five saved patterns.
It is currently March 29th, 2024, 8:41 am
Variable number of items in RSS feed?
-
- Posts: 4
- Joined: August 6th, 2010, 9:50 pm
-
- Developer
- Posts: 263
- Joined: July 31st, 2009, 2:23 pm
- Location: Tokyo, JPN
Re: Variable number of items in RSS feed?
I often use the method that used "Alternation" to solve a similar problem.
For example, this pattern means the one entry (contents of <item> tag), OR nothing
(?:(<item>.*</item>)|)
Then, If you connect these three pattern blocks, this pattern would mean like,
"three entries OR two entries OR one entry OR nothing"
(?:(<item>.*</item>)|)(?:(<item>.*</item>)|)(?:(<item>.*</item>)|)
If this approach is used in your example,
"(?:.*<title>(.*)<.*<link>(.*)<|)" is a one block, so if you need 6 entries,
This would not cause a matching error even if there is only one entry.
Note that this method may not be orthodox to be exact. but you can use this as easy-to-understand solution for such problem that unfixed number of items.
For example, this pattern means the one entry (contents of <item> tag), OR nothing
(?:(<item>.*</item>)|)
Then, If you connect these three pattern blocks, this pattern would mean like,
"three entries OR two entries OR one entry OR nothing"
(?:(<item>.*</item>)|)(?:(<item>.*</item>)|)(?:(<item>.*</item>)|)
If this approach is used in your example,
"(?:.*<title>(.*)<.*<link>(.*)<|)" is a one block, so if you need 6 entries,
Code: Select all
RegExp="(?siU)<item>(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)"
Note that this method may not be orthodox to be exact. but you can use this as easy-to-understand solution for such problem that unfixed number of items.
-
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Variable number of items in RSS feed?
This would make a very nice "Tips and Tricks" entry on the main site.kenz0 wrote:I often use the method that used "Alternation" to solve a similar problem.
For example, this pattern means the one entry (contents of <item> tag), OR nothing
(?:(<item>.*</item>)|)
Then, If you connect these three pattern blocks, this pattern would mean like,
"three entries OR two entries OR one entry OR nothing"
(?:(<item>.*</item>)|)(?:(<item>.*</item>)|)(?:(<item>.*</item>)|)
If this approach is used in your example,
"(?:.*<title>(.*)<.*<link>(.*)<|)" is a one block, so if you need 6 entries,This would not cause a matching error even if there is only one entry.Code: Select all
RegExp="(?siU)<item>(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)(?:.*<title>(.*)<.*<link>(.*)<|)"
Note that this method may not be orthodox to be exact. but you can use this as easy-to-understand solution for such problem that unfixed number of items.
-
- Posts: 4
- Joined: August 6th, 2010, 9:50 pm
Re: Variable number of items in RSS feed?
I gave the alternation a try but it didn't work. The log file shows:
DEBUG: (47:01:02.797) Refreshing (Name: "Tranquil\Weather" Ini: "NHC.ini")
DEBUG: (47:01:02.968) WebParser: Fetching URL: http://www.nhc.noaa.gov/index-at.xml
DEBUG: (47:01:03.108) WebParser: Finished URL: http://www.nhc.noaa.gov/index-at.xml
DEBUG: (47:01:03.108) WebParser: Matching error! (-1)
And the regexp is:
RegExp="(?siU)<title>(.*)</title>.*<link>(.*)</link>(?:.*<item>.*<title>(.*)</title>.*<link>(.*)</link>|)(?:.*<item>.*<title>(.*)</title>.*<link>(.*)</link>|)(?:.*<item>.*<title>(.*)</title>.*<link>(.*)</link>|)
The first title and link are always available, it's the title of the feed itself. After that the items are available. I'm sure I've done something wrong but I can't quite figure out the error.
DEBUG: (47:01:02.797) Refreshing (Name: "Tranquil\Weather" Ini: "NHC.ini")
DEBUG: (47:01:02.968) WebParser: Fetching URL: http://www.nhc.noaa.gov/index-at.xml
DEBUG: (47:01:03.108) WebParser: Finished URL: http://www.nhc.noaa.gov/index-at.xml
DEBUG: (47:01:03.108) WebParser: Matching error! (-1)
And the regexp is:
RegExp="(?siU)<title>(.*)</title>.*<link>(.*)</link>(?:.*<item>.*<title>(.*)</title>.*<link>(.*)</link>|)(?:.*<item>.*<title>(.*)</title>.*<link>(.*)</link>|)(?:.*<item>.*<title>(.*)</title>.*<link>(.*)</link>|)
The first title and link are always available, it's the title of the feed itself. After that the items are available. I'm sure I've done something wrong but I can't quite figure out the error.
-
- Developer
- Posts: 263
- Joined: July 31st, 2009, 2:23 pm
- Location: Tokyo, JPN
Re: Variable number of items in RSS feed?
You are forgetting to put a quotation mark at the end of line.
RegExp="(?siU)<title>(.*)</title>.*<link>(.*)</link>(?:.*<item>.*<title>(.*)</title>.*<link>(.*)</link>|)(?:.*<item>.*<title>(.*)</title>.*<link>(.*)</link>|)(?:.*<item>.*<title>(.*)</title>.*<link>(.*)</link>|)"
-
- Posts: 4
- Joined: August 6th, 2010, 9:50 pm
Re: Variable number of items in RSS feed?
Like I said, I'm sure I'm doing something wrong.
Works great now, thank you all for your help.
Works great now, thank you all for your help.
-
- Posts: 4
- Joined: August 6th, 2010, 9:50 pm
Re: Variable number of items in RSS feed?
One more problem with the variable feed:
The regex is working as far as not failing if it can't find enough pattern matches so that part is solved. The new problem is the way the data is displayed.
In the feed, there is a title and a link for the entire feed (Meter #0) and then a title and a link for each item (Meters #1 through #5). So right now I have six measures and six meters that pull the appropriate StringIndex to display and/or generate the link. Yesterday the storm feed went to its zero storm condition (two items) after the only storm in the Atlantic dissipated. However, the meters didn't update correctly. The title (Meter #0) is fine as are the first two meters (#1 and #2) correct and show just the message about no tropical cyclones and the Tropical Weather Outlook. But meters #3, #4, and #5 show old data instead of showing blank entries because no entries exist. The RSS feed itself has only the main title and two <item> entries.
How do I ensure that the new meters refresh properly to show the blank data?
The regex is working as far as not failing if it can't find enough pattern matches so that part is solved. The new problem is the way the data is displayed.
In the feed, there is a title and a link for the entire feed (Meter #0) and then a title and a link for each item (Meters #1 through #5). So right now I have six measures and six meters that pull the appropriate StringIndex to display and/or generate the link. Yesterday the storm feed went to its zero storm condition (two items) after the only storm in the Atlantic dissipated. However, the meters didn't update correctly. The title (Meter #0) is fine as are the first two meters (#1 and #2) correct and show just the message about no tropical cyclones and the Tropical Weather Outlook. But meters #3, #4, and #5 show old data instead of showing blank entries because no entries exist. The RSS feed itself has only the main title and two <item> entries.
How do I ensure that the new meters refresh properly to show the blank data?
-
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Variable number of items in RSS feed?
Coincidentally, this issue with WebParser will be fixed in the next beta 1.3 of Rainmeter.agcme wrote:One more problem with the variable feed:
The regex is working as far as not failing if it can't find enough pattern matches so that part is solved. The new problem is the way the data is displayed.
In the feed, there is a title and a link for the entire feed (Meter #0) and then a title and a link for each item (Meters #1 through #5). So right now I have six measures and six meters that pull the appropriate StringIndex to display and/or generate the link. Yesterday the storm feed went to its zero storm condition (two items) after the only storm in the Atlantic dissipated. However, the meters didn't update correctly. The title (Meter #0) is fine as are the first two meters (#1 and #2) correct and show just the message about no tropical cyclones and the Tropical Weather Outlook. But meters #3, #4, and #5 show old data instead of showing blank entries because no entries exist. The RSS feed itself has only the main title and two <item> entries.
How do I ensure that the new meters refresh properly to show the blank data?