It is currently October 22nd, 2019, 6:04 pm

How to Show a Custom Error Message

General topics related to Rainmeter.
Krishneel Chand
Posts: 14
Joined: March 30th, 2018, 12:33 am

How to Show a Custom Error Message

Krishneel Chand » April 9th, 2018, 3:08 am

I'm using webpaser in my skin and it works great but sometimes the website from which the data is taken is not updated on time and that causes the skin to have no output at all.

I was just wondering if there is a way to show a message like "Data not available" instead of it being blank.

Sometimes the website has 2/5 information that I want [stringindex 1 & 2 have data but 3,4,5 don't] but again since all the data is not present it doesn't show anything. How can I show the data that is present and show "data not available" for the rest?
User avatar
balala
Rainmeter Sage
Posts: 8878
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to Show a Custom Error Message

balala » April 9th, 2018, 8:01 am

Maybe using the Lookahead Assertions could help, but not knowing the URL you're talking about, probably no one can help. So, please post the code you have so far.
Krishneel Chand
Posts: 14
Joined: March 30th, 2018, 12:33 am

Re: How to Show a Custom Error Message

Krishneel Chand » April 9th, 2018, 9:27 am

It gets info from "Next Launch" on http://www.spaceflightinsider.com/launch-schedule/
Sometimes only half of the info is available e.g Mission Name, Date, etc. but others like location are missing. What is the best way to deal with a scenario like that when webparser doesn't get all the information.
Should I have separate webparser for each?

Code: Select all

[MeasureSite]
Measure=Plugin
Plugin=WebParser
URL=http://www.spaceflightinsider.com/launch-schedule/
RegExp=(?siU)<div class="cd_img".*'(.*)'.*src="(.*)".*<div class="cd_info".*"mission".*">(.*)</a></td>.*"provider">.*<img src="(.*)".*title="(.*)".*<th>Vehicle</th>.*<td class="vehicle">(.*)</td>.*<th>Time</th>.*<td>(.*) (.*) (.*):(.*):(.*) (.*)</td>.*<td>(.*)</td>
UpdateRate=3600
FinishAction=[!EnableMeasureGroup Countdown][!ShowMeterGroup Countdown]

;-------------------------------

[Measure_Operator_Logo]
Measure=WebParser
URL=[MeasureSite]
StringIndex=1
Download=1

[Measure_Vechicle_Img]
Measure=WebParser
URL=[MeasureSite]
StringIndex=2
Download=1

[Measure_Mission]
Measure=WebParser
URL=[MeasureSite]
StringIndex=3

[Measure_LSP_Logo]
Measure=WebParser
URL=[MeasureSite]
StringIndex=4
Download=1

[Measure_LSP]
Measure=WebParser
URL=[MeasureSite]
StringIndex=5

[Measure_Vehicle]
Measure=WebParser
URL=[MeasureSite]
StringIndex=6

[Measure_Day]
Measure=WebParser
URL=[MeasureSite]
StringIndex=7

[Measure_Month]
Measure=WebParser
URL=[MeasureSite]
StringIndex=8

[Measure_Hour]
Measure=WebParser
URL=[MeasureSite]
StringIndex=9

[Measure_Minute]
Measure=WebParser
URL=[MeasureSite]
StringIndex=10

[Measure_Second]
Measure=WebParser
URL=[MeasureSite]
StringIndex=11

[Measure_TimeZone]
Measure=WebParser
URL=[MeasureSite]
StringIndex=12

[Measure_Location]
Measure=WebParser
URL=[MeasureSite]
StringIndex=13
User avatar
balala
Rainmeter Sage
Posts: 8878
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to Show a Custom Error Message

balala » April 9th, 2018, 1:46 pm

Krishneel Chand wrote:Sometimes only half of the info is available e.g Mission Name, Date, etc. but others like location are missing. What is the best way to deal with a scenario like that when webparser doesn't get all the information.
Should I have separate webparser for each?
This is a possibility, but probably not the best one. You should have to read the whole expression by one. Using the Lookahead Assertions, the WebParser measures which find the appropriate strings would return those, while the others would return empty strings.
To use the Lookahead Assertions you have to rewrite the RegExp option of the parent WebParser measure (in this case this is the [MeasureSite] measure. Try the following RegExp:

Code: Select all

[MeasureSite]
...
RegExp=(?siU)<div class="cd_img".*'(.*)'.*src="(.*)".*<div class="cd_info".*(?(?=.*"mission).*".*<a href=".*">(.*)</a></td>).*"provider">(?(?=.*<img src).*="(.*)").*(?(?=.*title).*="(.*)")(?(?=.*<th>Vehicle).*</th>.*<td class="vehicle">(.*)</td>)(?(?=.*<th>Time).*</th>.*<td>(.*) (.*) (.*):(.*):(.*) (.*)</td>).*(?(?=.*<tr>).*<th>Location</th>.*<td>(.*)</td>)
Note that the above RegExp is just partially rewritten, further attempts to completely rewrite it will come soon. You can try to figure out what is happening, but the basic idea is the following: when there is a (?(?= expression if the expression up to the first closed parenthese exists, the measures tries to read the appropriate string, according to the RegExp. If what is under the ?= part of the code doesn't exist, the measures are returning empty strings. This way the measures will work, even if some parts of the expression are missing and will return either the appropriate strings, or empty strings.
Unfortunately I'm not sure at all the above RegExp is working well in all conditions. Depending on what part of the website code is missing, there could be (or even better, probably will be) cases when the measure won't work properly. The RegExp must be refined, when different situations come out. However the above expression can be a start.