It is currently March 29th, 2024, 10:01 am

WebParser captures outside of (.*)

Get help with creating, editing & fixing problems with skins
baerdric
Posts: 11
Joined: February 15th, 2017, 3:34 pm

WebParser captures outside of (.*)

Post by baerdric »

When reading the Wolfram site (I will post the text), my webparser regexp string which I thought should exclude the portions "<plaintext>" and "</plaintext>", captures those instead and displays them as %1 in my following Text Meter.

Further, when I try to divide the string up using the "|" (or even "\|"), it fails completely and gives me nothing in %2
RegExp=(?siU)<plaintext>(.*).*\|.*(.*)</plaintext>

Here is the skin, I have left in my appid for testing, please don't screw me over on that. I will change it when we are done.

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1

[MeasurePlanetData]
Measure=Plugin
Plugin=WebParser
URL=http://api.wolframalpha.com/v2/query?input=planets%20next%20rise&appid=EE3KPP-P6937TY54K&assumption=*C.planets-_*PlanetClass-&includepodid=PropertyRanking:PlanetData&format=plaintext
RegExp=(?siU)<plaintext>(.*)</plaintext>
UpdateRate=3600

[MeterData]
Meter=String
MeasureName=MeasurePlanetData
FontColor=255,122,255,255
FontFace=Arial
FontSize=12
AntiAlias=1
ClipString=1
StringAlign=Left
W=400
H=220
X=0
Y=0
Text=%1
The clear text of the page should be like this:

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='true'
    error='false'
    numpods='1'
    datatypes='Planet'
    timedout=''
    timedoutpods=''
    timing='4.155'
    parsetiming='0.399'
    parsetimedout='false'
    recalculate=''
    id='MSPa5061hi5ha5dfi89c08a00003giegi2e8752gaca'
    host='http://www3.wolframalpha.com'
    server='12'
    related='http://www3.wolframalpha.com/api/v2/relatedQueries.jsp?id=MSPa5071hi5ha5dfi89c08a00005g7743i6d865i35c&s=12'
    version='2.6'>
 <pod title='Table'
     scanner='Data'
     id='PropertyRanking:PlanetData'
     position='100'
     error='false'
     numsubpods='1'>
  <subpod title=''>
   <plaintext>Mercury | 7:10 am EST  |  Wednesday, February 22, 2017
Venus | 8:34 am EST  |  Wednesday, February 22, 2017
Mars | 9:17 am EST  |  Wednesday, February 22, 2017
Jupiter | 10:22 pm EST  |  Tuesday, February 21, 2017
Saturn | 3:30 am EST  |  Wednesday, February 22, 2017
Uranus | 9:27 am EST  |  Wednesday, February 22, 2017
Neptune | 7:49 am EST  |  Wednesday, February 22, 2017</plaintext>
  </subpod>
 </pod>
 <assumptions count='1'>
  <assumption type='Clash'
      word='planets'
      template='Assuming "${word}" is ${desc1}. Use as ${desc2} instead'
      count='3'>
   <value name='PlanetClass'
       desc=' referring to planets'
       input='*C.planets-_*PlanetClass-' />
   <value name='MinorPlanetClass'
       desc=' referring to minor planets'
       input='*C.planets-_*MinorPlanetClass-' />
   <value name='ExoplanetClass'
       desc=' referring to exoplanets'
       input='*C.planets-_*ExoplanetClass-' />
  </assumption>
 </assumptions>
 <sources count='1'>
  <source url='http://www.wolframalpha.com/sources/PlanetDataSourceInformationNotes.html'
      text='Planet data' />
 </sources>
</queryresult>
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: WebParser captures outside of (.*)

Post by jsmorley »

You have to use child WebParser measures with a StringIndex option on them to get the individual (captures) that you get in the parent measure with a RegExp option.

Code: Select all

[MeasurePlanetData]
Measure=Plugin
Plugin=WebParser
URL=http://api.wolframalpha.com/v2/query?input=planets%20next%20rise&appid=EE3KPP-P6937TY54K&assumption=*C.planets-_*PlanetClass-&includepodid=PropertyRanking:PlanetData&format=plaintext
RegExp=(?siU)<plaintext>(.*)</plaintext>
UpdateRate=3600

[MeasurePlaintext]
Measure=Plugin
Plugin=WebParser
URL=[MeasurePlanetData]
StringIndex=1

[MeterData]
Meter=String
MeasureName=MeasurePlaintext
FontColor=255,122,255,255
FontFace=Arial
FontSize=12
AntiAlias=1
ClipString=1
StringAlign=Left
W=400
H=220
X=0
Y=0
Text=%1
The way it works is that the "parent" will contain the full text that is encompassed by the RegExp, in this case, everything including the <plaintext> and </plaintext>. The (captures) are then parsed out into an array of string values identified by StringIndex numbers, which you access in "child" measures. Parent / child and StringIndex are fundamental to WebParser.
baerdric
Posts: 11
Joined: February 15th, 2017, 3:34 pm

Re: WebParser captures outside of (.*)

Post by baerdric »

Thanks, I was reading about "parent" and "child" but couldn't figure it out from the doc. You have cleared up that mystery for me, thanks. Two days of reading and wondering and growling.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: WebParser captures outside of (.*)

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
Mercury=.*Mercury \| (.*)  \|  [\w]+, [\w]+ [\d]{1,2}, [\d]{4}
Venus=.*Venus \| (.*)  \|  [\w]+, [\w]+ [\d]{1,2}, [\d]{4}
Mars=.*Mars \| (.*)  \|  [\w]+, [\w]+ [\d]{1,2}, [\d]{4}
Jupiter=.*Jupiter \| (.*)  \|  [\w]+, [\w]+ [\d]{1,2}, [\d]{4}
Saturn=.*Saturn \| (.*)  \|  [\w]+, [\w]+ [\d]{1,2}, [\d]{4}
Uranus=.*Uranus \| (.*)  \|  [\w]+, [\w]+ [\d]{1,2}, [\d]{4}
Neptune=.*Neptune \| (.*)  \|  [\w]+, [\w]+ [\d]{1,2}, [\d]{4}

[MeasurePlanetData]
Measure=Plugin
Plugin=WebParser
URL=http://api.wolframalpha.com/v2/query?input=planets%20next%20rise&appid=EE3KPP-P6937TY54K&assumption=*C.planets-_*PlanetClass-&includepodid=PropertyRanking:PlanetData&format=plaintext
RegExp=(?siU)<plaintext>#Mercury##Venus##Mars##Jupiter##Saturn##Uranus##Neptune#
UpdateRate=3600

[MeasureMercuryTime]
Measure=Plugin
Plugin=WebParser
URL=[MeasurePlanetData]
StringIndex=1

[MeasureVenusTime]
Measure=Plugin
Plugin=WebParser
URL=[MeasurePlanetData]
StringIndex=2

[MeasureMarsTime]
Measure=Plugin
Plugin=WebParser
URL=[MeasurePlanetData]
StringIndex=3

[MeasureJupiterTime]
Measure=Plugin
Plugin=WebParser
URL=[MeasurePlanetData]
StringIndex=4

[MeasureSaturnTime]
Measure=Plugin
Plugin=WebParser
URL=[MeasurePlanetData]
StringIndex=5

[MeasureUranusTime]
Measure=Plugin
Plugin=WebParser
URL=[MeasurePlanetData]
StringIndex=6

[MeasureNeptuneTime]
Measure=Plugin
Plugin=WebParser
URL=[MeasurePlanetData]
StringIndex=7

[MeterMercury]
Meter=String
MeasureName=MeasureMercuryTime
X=5
Y=5
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Mercury: %1

[MeterVenus]
Meter=String
MeasureName=MeasureVenusTime
X=0r
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Venus: %1

[MeterMars]
Meter=String
MeasureName=MeasureMarsTime
X=0r
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Mars: %1

[MeterJupiter]
Meter=String
MeasureName=MeasureJupiterTime
X=0r
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Jupiter: %1

[MeterSaturn]
Meter=String
MeasureName=MeasureSaturnTime
X=0r
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Saturn: %1

[MeterUranus]
Meter=String
MeasureName=MeasureUranusTime
X=0r
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Uranus: %1

[MeterNeptune]
Meter=String
MeasureName=MeasureNeptuneTime
X=0r
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Neptune: %1
1.jpg
You do not have the required permissions to view the files attached to this post.