It is currently June 16th, 2021, 12:02 pm

WebParser - Am I doing the right thing?

Help with creating, editing & fixing problems with skins
MaestroSky
Posts: 30
Joined: April 20th, 2021, 4:15 pm

WebParser - Am I doing the right thing?

Post by MaestroSky »

I encountered such a problem when the data on the site can be from 0 or more.
This is when the data is 0:

Code: Select all

{"status": "ok", " meta":{"quantity": 0}, " data":[]}
Here is when the data is 1 (example):

Code: Select all

{"status": "ok", " meta":{"count":1},"data":[{"attack_type":"tournament","front_id":"season_16_ru_tier10m","front_name":"season_16_ru_tier10m","competitor_id":413999,"time":1622745001,"vehicle_level":10,"province_id":"awka","type":"attack","province_name":"Авка"}]}
This is when the data is 2 (example), etc.:

Code: Select all

{"status":"ok","meta":{"count":2},"data":[{"attack_type":"tournament","front_id":"season_16_ru_tier10m","front_name":"season_16_ru_tier10m","competitor_id":413999,"time":1622745001,"vehicle_level":10,"province_id":"awka","type":"attack","province_name":"Авка"},{"attack_type":"auction","front_id":"season_16_ru_tier10m","front_name":"season_16_ru_tier10m","competitor_id":151881,"time":1622746801,"vehicle_level":10,"province_id":"gourcy","type":"attack","province_name":"Гоурцы"}]}
What to do in such situations? If I write RegExp= on 2 or more, then when the site information is only on 1 or 0, I do not receive data.

Code: Select all

[Variables]
Reg1="attack_type":.*,"front_id":".*","front_name":".*","competitor_id":.*,"time":(.*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"}]}

Reg2="attack_type":".*","front_id":".*","front_name":".*","competitor_id":.*,"time":(.*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"},.*"attack_type":.*,"front_id":".*","front_name":".*","competitor_id":.*,"time":(.*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"}]}

Reg3="attack_type":.*,"front_id":".*","front_name":".*","competitor_id":.*,"time":(.*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"},.*"attack_type":".*","front_id":".*","front_name":".*","competitor_id":.*,"time":(.*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"},.*"attack_type":.*,"front_id":".*","front_name":".*","competitor_id":.*,"time":.(*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"}]}




[Count]
Measure=WebParser
URL=https://api.worldoftanks.ru/wot/globalmap/clanbattles/?application_id=bf049cf6db102d4f0536904348d02500&clan_id=[&MeasureTegClanID]
RegExp={"status":"ok","meta":{"count":(.*)},"data":[]} 
IfCondition=(Count = 1) || (Count = 2) || (Count = 3)
IfTrueAction=[!SetOption Time RegExp "#Reg1#"]
IfTrueAction2=[!SetOption Time RegExp "#Reg2#"]
IfTrueAction3=[!SetOption Time RegExp "#Reg3#"]
FinishAction=[!EnableMeasure "Time"][!CommandMeasure "Time" "Update"]
UpdateDivider=-1
DynamicVariables=1

[Time]
Measure=WebParser
URL=https://api.worldoftanks.ru/wot/globalmap/clanbattles/?application_id=bf049cf6db102d4f0536904348d02500&clan_id=[&MeasureTegClanID]
RegExp=[Count]
DynamicVariables=1

User avatar
Yincognito
Posts: 3184
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser - Am I doing the right thing?

Post by Yincognito »

MaestroSky wrote: June 4th, 2021, 12:05 pmWhat to do in such situations? If I write RegExp= on 2 or more, then when the site information is only on 1 or 0, I do not receive data.
You're approaching this the wrong way. There's no need to write different regexes for each case (e.g. populated by 0, 1, 2 or more "items") - it's enough to use a (?(?=condition)pattern) lookahead construct (see here under the Lookahead Assertions paragraph) to get the maximum possible number of "items", and just react accordingly in the code if some of those WebParser child measures are not populated (e.g. if the source contains fewer "items" than maximum). For this case, I used local versions of your site responses (saved as Unicode in plain Notepad, in order to have the cyrillic characters written correctly!), where I corrected some typos you had regarding spaces (\s in regex) - feel free to change the URL back to an online source (and remove the CodePage option as well in the process):

[SkinFolder]\@Resources\WOT0.txt:

Code: Select all

{"status":"ok","meta":{"quantity":0},"data":[]}
[SkinFolder]\@Resources\WOT1.txt:

Code: Select all

{"status":"ok","meta":{"count":1},"data":[{"attack_type":"tournament","front_id":"season_16_ru_tier10m","front_name":"season_16_ru_tier10m","competitor_id":413999,"time":1622745001,"vehicle_level":10,"province_id":"awka","type":"attack","province_name":"Авка"}]}
[SkinFolder]\@Resources\WOT2.txt:

Code: Select all

{"status":"ok","meta":{"count":2},"data":[{"attack_type":"tournament","front_id":"season_16_ru_tier10m","front_name":"season_16_ru_tier10m","competitor_id":413999,"time":1622745001,"vehicle_level":10,"province_id":"awka","type":"attack","province_name":"Авка"},{"attack_type":"auction","front_id":"season_16_ru_tier10m","front_name":"season_16_ru_tier10m","competitor_id":151881,"time":1622746801,"vehicle_level":10,"province_id":"gourcy","type":"attack","province_name":"Гоурцы"}]}
And the skin code (bear in mind that the patterns don't take possible spaces into account, but those are easy to add using \s* where needed anyway):

Code: Select all

[Variables]
WOTIndex=0
Item=(?(?=.*\{).*\{"attack_type":.*,"front_id":".*","front_name":".*","competitor_id":.*,"time":(.*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"\},?)
WOTRegEx=(?siU)^.*\{"status":.*,"meta":\{"(?:quantity|count)":(.*)\},"data":\[#Item##Item##Item#.*\]\}.*$

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[WOT]
Measure=WebParser
URL="file://#@#WOT#WOTIndex#.txt"
CodePage=1200
RegExp="#WOTRegEx#"
LogSubstringErrors=0
FinishAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
OnConnectErrorAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
OnRegExpErrorAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
UpdateRate=-1
DynamicVariables=1

[Count]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=1
UpdateDivider=-1
DynamicVariables=1

[Time1]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=2
UpdateDivider=-1
DynamicVariables=1

[Time2]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=3
UpdateDivider=-1
DynamicVariables=1

[Time3]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=4
UpdateDivider=-1
DynamicVariables=1

---Meters---

[CountText]
Group=WOTGroup
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Count
Text="Count: %1"
UpdateDivider=-1
DynamicVariables=1

[Time1Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Time1
Text="Time1: %1"
UpdateDivider=-1
DynamicVariables=1

[Time2Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Time2
Text="Time2: %1"
UpdateDivider=-1
DynamicVariables=1

[Time3Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Time3
Text="Time3: %1"
UpdateDivider=-1
DynamicVariables=1
You can, of course, copy-paste as many #Item# variables in the WOTRegEx variable - I used 3 to show that it works even if you have less (by changing the value of the WOTIndex variable). Also, make sure that you manage the update of a WebParser parent measure using UpdateRate and not UpdateDivider - it's safer that way.

P.S. If there is something you don't understand or I didn't covered above regarding the code or the approach, feel free to ask.
MaestroSky
Posts: 30
Joined: April 20th, 2021, 4:15 pm

Re: WebParser - Am I doing the right thing?

Post by MaestroSky »

Yincognito wrote: June 5th, 2021, 11:58 am You're approaching this the wrong way. There's no need to write different regexes for each case (e.g. populated by 0, 1, 2 or more "items") - it's enough to use a (?(?=condition)pattern) lookahead construct (see here under the Lookahead Assertions paragraph) to get the maximum possible number of "items", and just react accordingly in the code if some of those WebParser child measures are not populated (e.g. if the source contains fewer "items" than maximum). For this case, I used local versions of your site responses (saved as Unicode in plain Notepad, in order to have the cyrillic characters written correctly!), where I corrected some typos you had regarding spaces (\s in regex) - feel free to change the URL back to an online source (and remove the CodePage option as well in the process):

[SkinFolder]\@Resources\WOT0.txt:

Code: Select all

{"status":"ok","meta":{"quantity":0},"data":[]}
[SkinFolder]\@Resources\WOT1.txt:

Code: Select all

{"status":"ok","meta":{"count":1},"data":[{"attack_type":"tournament","front_id":"season_16_ru_tier10m","front_name":"season_16_ru_tier10m","competitor_id":413999,"time":1622745001,"vehicle_level":10,"province_id":"awka","type":"attack","province_name":"Авка"}]}
[SkinFolder]\@Resources\WOT2.txt:

Code: Select all

{"status":"ok","meta":{"count":2},"data":[{"attack_type":"tournament","front_id":"season_16_ru_tier10m","front_name":"season_16_ru_tier10m","competitor_id":413999,"time":1622745001,"vehicle_level":10,"province_id":"awka","type":"attack","province_name":"Авка"},{"attack_type":"auction","front_id":"season_16_ru_tier10m","front_name":"season_16_ru_tier10m","competitor_id":151881,"time":1622746801,"vehicle_level":10,"province_id":"gourcy","type":"attack","province_name":"Гоурцы"}]}
And the skin code (bear in mind that the patterns don't take possible spaces into account, but those are easy to add using \s* where needed anyway):

Code: Select all

[Variables]
WOTIndex=0
Item=(?(?=.*\{).*\{"attack_type":.*,"front_id":".*","front_name":".*","competitor_id":.*,"time":(.*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"\},?)
WOTRegEx=(?siU)^.*\{"status":.*,"meta":\{"(?:quantity|count)":(.*)\},"data":\[#Item##Item##Item#.*\]\}.*$

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[WOT]
Measure=WebParser
URL="file://#@#WOT#WOTIndex#.txt"
CodePage=1200
RegExp="#WOTRegEx#"
LogSubstringErrors=0
FinishAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
OnConnectErrorAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
OnRegExpErrorAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
UpdateRate=-1
DynamicVariables=1

[Count]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=1
UpdateDivider=-1
DynamicVariables=1

[Time1]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=2
UpdateDivider=-1
DynamicVariables=1

[Time2]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=3
UpdateDivider=-1
DynamicVariables=1

[Time3]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=4
UpdateDivider=-1
DynamicVariables=1

---Meters---

[CountText]
Group=WOTGroup
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Count
Text="Count: %1"
UpdateDivider=-1
DynamicVariables=1

[Time1Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Time1
Text="Time1: %1"
UpdateDivider=-1
DynamicVariables=1

[Time2Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Time2
Text="Time2: %1"
UpdateDivider=-1
DynamicVariables=1

[Time3Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Time3
Text="Time3: %1"
UpdateDivider=-1
DynamicVariables=1
You can, of course, copy-paste as many #Item# variables in the WOTRegEx variable - I used 3 to show that it works even if you have less (by changing the value of the WOTIndex variable). Also, make sure that you manage the update of a WebParser parent measure using UpdateRate and not UpdateDivider - it's safer that way.

P.S. If there is something you don't understand or I didn't covered above regarding the code or the approach, feel free to ask.
Thank you very much for pointing out the right direction in this matter.
I will try to correct it according to your suggestions.
User avatar
Yincognito
Posts: 3184
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser - Am I doing the right thing?

Post by Yincognito »

MaestroSky wrote: June 5th, 2021, 5:52 pm Thank you very much for pointing out the right direction in this matter.
I will try to correct it according to your suggestions.
No problem - hopefully it will go smooth and successful. ;-)
MaestroSky
Posts: 30
Joined: April 20th, 2021, 4:15 pm

Re: WebParser - Am I doing the right thing?

Post by MaestroSky »

Yincognito wrote: June 5th, 2021, 6:24 pm No problem - hopefully it will go smooth and successful. ;-)
A couple of days later, I got to this code.
Faced with such a problem when I increased the number from 3 to 5 and translated all this time from UNIX to Windows does not translate 3 point. Rechecked 1005000 times and all the same.
Due to the fact that the page from which I take information is constantly changing, I will not be able to give a clear result that it will continue to work.

What I added for the conversion:

Code: Select all

[MeasureUnixTimeStart]
Measure=Time
TimeStamp=03:00:00 01/01/1970
TimeStampFormat=%H:%M:%S %d/%m/%Y 
FormatLocale=Local
UpdateDivider=-1
DynamicVariables=1
And to everyone Time1, Time2, Time3 ...

Code: Select all

[WindowsTime1] 
Measure=Calc
Formula=[Time1:Timestamp]+[MeasureUnixTimeStart:Timestamp]
DynamicVariables=1

[MeasureTimeConvert1]
Measure=Time
TimeStamp=[WindowsTime1]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
DynamicVariables=1
Meters i double-checked everything..

I also tried to make a real-time check that would filter out the time that has already passed from the list and show the closest to the current time. But I didn't get anything either. I don't even understand how to implement it.

I may have made a mistake somewhere in the first case, but I'm more interested in how to implement the check. I will be grateful for any assistance or to direct me on a path that can help me.
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Posts: 3184
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser - Am I doing the right thing?

Post by Yincognito »

MaestroSky wrote: June 8th, 2021, 8:41 pmFaced with such a problem when I increased the number from 3 to 5 and translated all this time from UNIX to Windows does not translate 3 point.
This might be because you forgot to add the new measures / meters to the WOTGroup groups. Those are updated each time the [WOT] WebParser measure is interrogating the source URL (see its FinishAction). It could be another reason as well, although I can't think of one, not having the whole code in front of me (the code you captured in the screenhot seems fine though). Anyway, for me it works, see below.
MaestroSky wrote: June 8th, 2021, 8:41 pmI also tried to make a real-time check that would filter out the time that has already passed from the list and show the closest to the current time.
So, you want to get the closest time AFTER the current time, right? You know, since the times before the current time are all excluded, and only the closest remains from those times which are after the current time, if I understood correctly. Check this out (local test in my case, you know the system):
Test_1.0.0.rmskin

Code: Select all

[Variables]
WOTIndex=5
Item=(?(?=.*\{).*\{"attack_type":.*,"front_id":".*","front_name":".*","competitor_id":.*,"time":(.*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"\},?)
WOTRegEx=(?siU)^.*\{"status":.*,"meta":\{"(?:quantity|count)":(.*)\},"data":\[#Item##Item##Item##Item##Item#\]\}.*$
MinTimeDifference=9223372036854775807
ClosestToCurrentTimeIndex=0

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[MeasureUnixTimeStart]
Measure=Time
TimeStamp=03:00:00 01/01/1970
TimeStampFormat=%H:%M:%S %d/%m/%Y 
FormatLocale=Local
UpdateDivider=-1
DynamicVariables=1

[CurrentTime]
Measure=Time
Format=%H:%M:%S %d/%m/%Y
FormatLocale=Local
OnUpdateAction=[!SetVariable MinTimeDifference 9223372036854775807]

[WOT]
Measure=WebParser
URL="file://#@#WOT#WOTIndex#.txt"
CodePage=1200
RegExp="#WOTRegEx#"
LogSubstringErrors=0
FinishAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
OnConnectErrorAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
OnRegExpErrorAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
UpdateRate=-1
DynamicVariables=1

[Count]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=1
UpdateDivider=-1
DynamicVariables=1

[Time1]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=2
UpdateDivider=-1
DynamicVariables=1

[Time2]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=3
UpdateDivider=-1
DynamicVariables=1

[Time3]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=4
UpdateDivider=-1
DynamicVariables=1

[Time4]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=5
UpdateDivider=-1
DynamicVariables=1

[Time5]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=6
UpdateDivider=-1
DynamicVariables=1

[WindowsTime1] 
Group=WOTGroup
Measure=Calc
Formula=([Time1:Timestamp]+[MeasureUnixTimeStart:Timestamp])
IfCondition=((Abs([CurrentTime:Timestamp]-[WindowsTime1:Timestamp]))<#MinTimeDifference#) && ([WindowsTime1:Timestamp]>=[CurrentTime:Timestamp])
IfTrueAction=[!SetVariable ClosestToCurrentTimeIndex 1][!SetVariable MinTimeDifference (Abs([CurrentTime:Timestamp]-[WindowsTime1:Timestamp]))]
IfConditionMode=1
DynamicVariables=1

[MeasureTimeConvert1]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime1]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[WindowsTime2] 
Group=WOTGroup
Measure=Calc
Formula=([Time2:Timestamp]+[MeasureUnixTimeStart:Timestamp])
IfCondition=((Abs([CurrentTime:Timestamp]-[WindowsTime2:Timestamp]))<#MinTimeDifference#) && ([WindowsTime2:Timestamp]>=[CurrentTime:Timestamp])
IfTrueAction=[!SetVariable ClosestToCurrentTimeIndex 2][!SetVariable MinTimeDifference (Abs([CurrentTime:Timestamp]-[WindowsTime2:Timestamp]))]
IfConditionMode=1
DynamicVariables=1

[MeasureTimeConvert2]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime2]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[WindowsTime3] 
Group=WOTGroup
Measure=Calc
Formula=([Time3:Timestamp]+[MeasureUnixTimeStart:Timestamp])
IfCondition=((Abs([CurrentTime:Timestamp]-[WindowsTime3:Timestamp]))<#MinTimeDifference#) && ([WindowsTime3:Timestamp]>=[CurrentTime:Timestamp])
IfTrueAction=[!SetVariable ClosestToCurrentTimeIndex 3][!SetVariable MinTimeDifference (Abs([CurrentTime:Timestamp]-[WindowsTime3:Timestamp]))]
IfConditionMode=1
DynamicVariables=1

[MeasureTimeConvert3]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime3]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[WindowsTime4] 
Group=WOTGroup
Measure=Calc
Formula=([Time4:Timestamp]+[MeasureUnixTimeStart:Timestamp])
IfCondition=((Abs([CurrentTime:Timestamp]-[WindowsTime4:Timestamp]))<#MinTimeDifference#) && ([WindowsTime4:Timestamp]>=[CurrentTime:Timestamp])
IfTrueAction=[!SetVariable ClosestToCurrentTimeIndex 4][!SetVariable MinTimeDifference (Abs([CurrentTime:Timestamp]-[WindowsTime4:Timestamp]))]
IfConditionMode=1
DynamicVariables=1

[MeasureTimeConvert4]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime4]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[WindowsTime5]
Group=WOTGroup
Measure=Calc
Formula=([Time5:Timestamp]+[MeasureUnixTimeStart:Timestamp])
IfCondition=((Abs([CurrentTime:Timestamp]-[WindowsTime5:Timestamp]))<#MinTimeDifference#) && ([WindowsTime5:Timestamp]>=[CurrentTime:Timestamp])
IfTrueAction=[!SetVariable ClosestToCurrentTimeIndex 5][!SetVariable MinTimeDifference (Abs([CurrentTime:Timestamp]-[WindowsTime5:Timestamp]))]
IfConditionMode=1
DynamicVariables=1

[MeasureTimeConvert5]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime5]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[MeasureTimeConvert0]
Group=WOTGroup
Measure=String
String="None"

[MinTimeDifferenceConvert]
Group=WOTGroup
Measure=UpTime
SecondsValue=#MinTimeDifference#
Format="%4!i!d %3!i!h %2!i!m %1!i!s"
RegExpSubstitute=1
Substitute="^579025220d 15h 30m 8s$":"None"
DynamicVariables=1

---Meters---

[CountText]
Group=WOTGroup
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Count
Text="Count: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert1Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert1
Text="Time1: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert2Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert2
Text="Time2: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert3Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert3
Text="Time3: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert4Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert4
Text="Time4: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert5Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert5
Text="Time5: %1"
UpdateDivider=-1
DynamicVariables=1

[ClosestToCurrentTimeText]
Group=WOTGroup
Meter=String
Y=10R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert#ClosestToCurrentTimeIndex#
MeasureName2=MinTimeDifferenceConvert
Text="Closest After Current Time#CRLF# Item: #ClosestToCurrentTimeIndex##CRLF# Time: %1#CRLF# Diff: %2"
DynamicVariables=1
What I did was:
- add a very large MinTimeDifference variable (maximum of INT64 value used), initialized every time the [CurrentTime] measure (see below) updates, so that on querying the source URL, it is always bigger than the absolute value of the difference between the current time and a time of our choosing (e.g. [WindowsTime1], [WindowsTime2], [WindowsTime3] and so on)
- add a ClosestToCurrentTimeIndex variable where we would store the "index" of the item / measure whose time is the closest after the current time, or 0 if no such measure qualifies
- add a [CurrentTime] measure holding the current time, which we can then use in computing time related stuff
- add a condition in each [WindowsTime...] measure to test if that time is the closest after the current time, by comparing to the MinTimeDifference variable (this will always store the current minimum time difference, so when we found a "new" minimum we update this variable accordingly, along with the "index" of the measure on which we found the said minimum)
- add some RegExp Substitutes to handle the "error" or "none" cases in various measures (including the dummy [MeasureTimeConvert0] measure to avoid the error in the final [ClosestToCurrentTimeText] meter when the "index" above has the default / none value of 0)
- add a [MinTimeDifferenceConvert] Uptime measure to optionally display the actual minimum difference in a readable fashion, if it exists
- finally, add the [ClosestToCurrentTimeText] meter to display the result, using the "index" I mentioned earlier to associate the proper measure to this meter in MeasureName

The result (the 3rd time works, as you can see; in the upper right corner is one of my skins showing the current time, to check the math):
Closest After Current Time.jpg
Hopefully I understood what you wanted properly. I attached the packed skin because it was easier than adding the contents of every WOT....txt mini file that I used in my local tests.

P.S. If I only wanted to get the minimum time difference between the current time and the other time measures in your skin, I could have easily used the Min() formula method mentioned by death.crafter in the related thread and forget about using an up to date MinTimeDifference variable and IfConditions in every time measure, but I wanted to store the item / measure "index" of that closest time as well, and simply using Min() wouldn't have helped on that, since it doesn't retain which of the values (e.g. the 2nd, or the 5th, and so on) is the minimum, it just provides the result value. For the record, this is the Min() variant:

Code: Select all

[Variables]
WOTIndex=5
Item=(?(?=.*\{).*\{"attack_type":.*,"front_id":".*","front_name":".*","competitor_id":.*,"time":(.*),"vehicle_level":.*,"province_id":".*","type":".*","province_name":".*"\},?)
WOTRegEx=(?siU)^.*\{"status":.*,"meta":\{"(?:quantity|count)":(.*)\},"data":\[#Item##Item##Item##Item##Item#\]\}.*$

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[MeasureUnixTimeStart]
Measure=Time
TimeStamp=03:00:00 01/01/1970
TimeStampFormat=%H:%M:%S %d/%m/%Y 
FormatLocale=Local
UpdateDivider=-1
DynamicVariables=1

[CurrentTime]
Measure=Time
Format=%H:%M:%S %d/%m/%Y
FormatLocale=Local

[WOT]
Measure=WebParser
URL="file://#@#WOT#WOTIndex#.txt"
CodePage=1200
RegExp="#WOTRegEx#"
LogSubstringErrors=0
FinishAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
OnConnectErrorAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
OnRegExpErrorAction=[!UpdateMeasureGroup WOTGroup][!UpdateMeterGroup WOTGroup][!Redraw]
UpdateRate=-1
DynamicVariables=1

[Count]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=1
UpdateDivider=-1
DynamicVariables=1

[Time1]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=2
UpdateDivider=-1
DynamicVariables=1

[Time2]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=3
UpdateDivider=-1
DynamicVariables=1

[Time3]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=4
UpdateDivider=-1
DynamicVariables=1

[Time4]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=5
UpdateDivider=-1
DynamicVariables=1

[Time5]
Group=WOTGroup
Measure=WebParser
URL=[WOT]
StringIndex=6
UpdateDivider=-1
DynamicVariables=1

[WindowsTime1] 
Group=WOTGroup
Measure=Calc
Formula=([Time1:Timestamp]+[MeasureUnixTimeStart:Timestamp])
DynamicVariables=1

[MeasureTimeConvert1]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime1]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[WindowsTime2] 
Group=WOTGroup
Measure=Calc
Formula=([Time2:Timestamp]+[MeasureUnixTimeStart:Timestamp])
DynamicVariables=1

[MeasureTimeConvert2]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime2]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[WindowsTime3] 
Group=WOTGroup
Measure=Calc
Formula=([Time3:Timestamp]+[MeasureUnixTimeStart:Timestamp])
DynamicVariables=1

[MeasureTimeConvert3]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime3]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[WindowsTime4] 
Group=WOTGroup
Measure=Calc
Formula=([Time4:Timestamp]+[MeasureUnixTimeStart:Timestamp])
DynamicVariables=1

[MeasureTimeConvert4]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime4]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[WindowsTime5]
Group=WOTGroup
Measure=Calc
Formula=([Time5:Timestamp]+[MeasureUnixTimeStart:Timestamp])
DynamicVariables=1

[MeasureTimeConvert5]
Group=WOTGroup
Measure=Time
TimeStamp=[WindowsTime5]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

[MinTimeDifference]
Group=WOTGroup
Measure=Calc
Formula=(Min(Min(Min(Min(([WindowsTime1:Timestamp]<[CurrentTime:Timestamp]?999999999:([WindowsTime1:Timestamp]-[CurrentTime:Timestamp])),([WindowsTime2:Timestamp]<[CurrentTime:Timestamp]?999999999:([WindowsTime2:Timestamp]-[CurrentTime:Timestamp]))),([WindowsTime3:Timestamp]<[CurrentTime:Timestamp]?999999999:([WindowsTime3:Timestamp]-[CurrentTime:Timestamp]))),([WindowsTime4:Timestamp]<[CurrentTime:Timestamp]?999999999:([WindowsTime4:Timestamp]-[CurrentTime:Timestamp]))),([WindowsTime5:Timestamp]<[CurrentTime:Timestamp]?999999999:([WindowsTime5:Timestamp]-[CurrentTime:Timestamp]))))
DynamicVariables=1

[MinTimeDifferenceConvert]
Group=WOTGroup
Measure=UpTime
SecondsValue=[MinTimeDifference]
Format="%4!i!d %3!i!h %2!i!m %1!i!s"
RegExpSubstitute=1
Substitute="^11574d 1h 46m 39s$":"None"
DynamicVariables=1

[MinTime]
Group=WOTGroup
Measure=Calc
Formula=([MinTimeDifference:Timestamp]=999999999?[MeasureUnixTimeStart:Timestamp]:([CurrentTime:Timestamp]+[MinTimeDifference:Timestamp]))
DynamicVariables=1

[MinTimeConvert]
Group=WOTGroup
Measure=Time
TimeStamp=[MinTime]
FormatLocale=Local
Format=%H:%M:%S %d/%m/%Y
RegExpSubstitute=1
Substitute="^03:00:00 01\/01\/1970$":"None"
DynamicVariables=1

---Meters---

[CountText]
Group=WOTGroup
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Count
Text="Count: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert1Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert1
Text="Time1: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert2Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert2
Text="Time2: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert3Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert3
Text="Time3: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert4Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert4
Text="Time4: %1"
UpdateDivider=-1
DynamicVariables=1

[TimeConvert5Text]
Group=WOTGroup
Meter=String
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTimeConvert5
Text="Time5: %1"
UpdateDivider=-1
DynamicVariables=1

[ClosestAfterCurrentTimeText]
Group=WOTGroup
Meter=String
Y=10R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MinTimeConvert
MeasureName2=MinTimeDifferenceConvert
Text="Closest After Current Time#CRLF# Time: %1#CRLF# Diff: %2"
DynamicVariables=1
You do not have the required permissions to view the files attached to this post.
MaestroSky
Posts: 30
Joined: April 20th, 2021, 4:15 pm

Re: WebParser - Am I doing the right thing?

Post by MaestroSky »

Yincognito wrote: June 9th, 2021, 1:16 am
Thank you for the help you gave me.
Here is a small fragment of the video of your code in the work of the skin. This is still only a beta version, and much more needs to be finalized.
But now it works the way I planned it for myself.
User avatar
Yincognito
Posts: 3184
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser - Am I doing the right thing?

Post by Yincognito »

MaestroSky wrote: June 9th, 2021, 9:28 pm Thank you for the help you gave me.
Here is a small fragment of the video of your code in the work of the skin. This is still only a beta version, and much more needs to be finalized.
But now it works the way I planned it for myself.
Wow, it looks really nice - good job! :thumbup: I'm glad I could help you with this - all the best in the future development of your skin. ;-)