It is currently April 27th, 2024, 5:57 am

WebParser XMLHttpRequest for weather forecast

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser XMLHttpRequest for weather forecast

Post by balala »

emp00 wrote: March 16th, 2024, 11:40 am The "vor" button (loading +24h data) is indeed not so easy to see, here you go:
Are you still interested in this? Or in meantime you did got a solution? Sorry, but today had no enough time to work with it and in meantime the discussion has became way too long.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser XMLHttpRequest for weather forecast

Post by Yincognito »

emp00 wrote: March 16th, 2024, 11:40 amIf you have a concrete skin example showing an hourly ckoud+UV trend, similar to the "Grafik+" above and for the next 3 days - this would be perfect. Otherwise I'm willing to make my own skin (preferably by modifying my AstroWeather variant), but I need some help / documentation how to parse (only) the hourly cloud cover & UV-index numerical data. I can work best with skin examples and modify them - starting from scratch is hard for me.
Well, starting from scratch is my favorite, mainly because it's way easier than getting familiar with and debugging some other skin, and you wanted some examples, so here you go (try your best to use the included CoverUV.json local file as the URL for testing, so that you don't poll weather.com excessively and have surprises like getting your IP banned; once you're done with the testing, you completed the skin, or just want to see if the "online" version works, you can uncomment the 1st URL option below and comment out the 2nd one):
CoverUV_1.0.0.rmskin
Code (needs a ...\@Resources\CoverUV.json sample, works with the response here as well):

Code: Select all

; DPat = Day  Pattern (capture one 24 hour set from the current data field)
; HPat = Hour Pattern (capture each of the 24 hour values from current day)

[Variables]
Lati=33.74
Long=-84.39
Unit=m
Lang=en-CA
ApiK=21d8a80b3d6b444998a80b3d6b1449d3
DPat=(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)
HPat=(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*)

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

---Measures---

; Use the local file for frequent testing, and the online address once you finished the skin

[CoverUV]
Measure=WebParser
;URL=https://api.weather.com/v3/wx/forecast/hourly/15day?geocode=#Lati#,#Long#&format=json&units=#Unit#&language=#Lang#&apiKey=#ApiK#
URL=file://#@#CoverUV.json
UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36
RegExp=(?siU)\{"cloudCover":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"dayOfWeek":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"uvIndex":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"validTimeLocal":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],
UpdateRate=600

; StringIndex  = (Days * Field + Day)   <--   where Days = 15, Field = 0 to 3 = cloudCover to validTimeLocal, Day = 1 to 15
; StringIndex2 = Hour                   <--   where Hour = 1 to 24, from the current hour

; Example: Day 1 Hour 1

[CloudCoverD1H1]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*0+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[DayOfWeekD1H1]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*1+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[UVIndexD1H1]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*2+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[DateTimeD1H1]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*3+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

; Example: Day 1 Hour 2

[CloudCoverD1H2]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*0+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[DayOfWeekD1H2]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*1+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[UVIndexD1H2]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*2+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[DateTimeD1H2]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*3+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

; Example: Day 13 Hour 21

[CloudCoverD13H21]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*0+13)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[DayOfWeekD13H21]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*1+13)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[UVIndexD13H21]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*2+13)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[DateTimeD13H21]
Measure=WebParser
URL=[CoverUV]
StringIndex=(15*3+13)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

---Meters---

[Result]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=CloudCoverD1H1
MeasureName2=DayOfWeekD1H1
MeasureName3=UVIndexD1H1
MeasureName4=DateTimeD1H1
MeasureName5=CloudCoverD1H2
MeasureName6=DayOfWeekD1H2
MeasureName7=UVIndexD1H2
MeasureName8=DateTimeD1H2
MeasureName9=CloudCoverD13H21
MeasureName10=DayOfWeekD13H21
MeasureName11=UVIndexD13H21
MeasureName12=DateTimeD13H21
Text=Cloud Cover = %1%#CRLF#Day Of Week = %2#CRLF#UV Index    = %3#CRLF#Date & Time = %4#CRLF##CRLF#Cloud Cover = %5%#CRLF#Day Of Week = %6#CRLF#UV Index    = %7#CRLF#Date & Time = %8#CRLF##CRLF#Cloud Cover = %9%#CRLF#Day Of Week = %10#CRLF#UV Index    = %11#CRLF#Date & Time = %12
DynamicVariables=1
Details in the comments from the code. As for the graph, use the values from the CloudCover or UVIndex measures in some Calc measures, set the MinValue and MaxValue properly on those Calcs to retrieve percentual values from them, then use the Calcs in Bar meters. The above code is easy to adapt, but you'll end up with a huge skin and serious space issues for hourly values (15 days x 24 hours x 4 fields x 3 sections, you get the idea). One way to deal with it would be to only display one day at a time.

P.S. It turned out 170 lines instead of just 50, but when posting earlier I didn't count more than 2 examples and the day of week or the date-time fields. In any case, it just needs a lot of copy pasting, so no big deal.
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
emp00
Posts: 83
Joined: October 7th, 2022, 8:08 pm

Re: WebParser XMLHttpRequest for weather forecast

Post by emp00 »

Thanks so much guys - all of you, this forum is superb!

I have now closely checked the weather data quality and features for my purpose and clearly, weather.com is not as good as the data from api.open-meteo.com (@eclectic-tech, this was your idea, THANK YOU, this service is excellent!). Best-of-all, open-meteo.com provides hourly data even for PV / solar relevant parameters, especially even "global tilted irradiance" which is giving a superb prognosis on W/m² solar production of the coming days for my panels! See screenshot below.

This api-call directly pulls the clean data as a 7 day / hourly forcast, as an example for a location in Italy:
https://api.open-meteo.com/v1/forecast?latitude=45.0&longitude=12.0&hourly=temperature_2m,precipitation_probability,cloud_cover,global_tilted_irradiance&timezone=Europe%2FBerlin&tilt=35&azimuth=-30

My goal is now clear - A skin displaying such a clean trend graph from the open-meteo.com data. Main focus is the "global tilted irradiance", the other parameters are "nice to have". However, honestly, I have no clue how to make line graphs with Rainmeter (7 days * 12 hours = 84 datapoints: fixed y-axis would be OK). This is super-easy in Excel but I have a feeling this might be "too much" for Rainmeter?

Image
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: WebParser XMLHttpRequest for weather forecast

Post by eclectic-tech »

Excellent!

I thought you would appreciate the solar radiation data provided in watts/meter2.

The data from Weather.com provided by Yincognito's method is good (thanks for that!), but I don't think TWC provides the type of data you are looking to use in your project.

The display of that data is going to be the real work; I would look at the line shape meter to provide a starting point.

Glad you are getting closer to the desired finished result. :thumbup:
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser XMLHttpRequest for weather forecast

Post by Yincognito »

eclectic-tech wrote: March 16th, 2024, 9:38 pmThe data from Weather.com provided by Yincognito's method is good (thanks for that!), but I don't think TWC provides the type of data you are looking to use in your project.
Well, it doesn't really matter whether TWC provides the radiance or not, my sample code above can easily be applied to the open-meteo API response, it's just a matter of adjusting some variables, the URL and the similar structure to be found in the JSON (e.g. the 1st RegExp option) according to the fields provided by the open-meteo API. After all, the OP said he works best by modifying skin examples, and since the example has been given... :sly:
emp00 wrote: March 16th, 2024, 9:16 pmHowever, honestly, I have no clue how to make line graphs with Rainmeter (7 days * 12 hours = 84 datapoints: fixed y-axis would be OK). This is super-easy in Excel but I have a feeling this might be "too much" for Rainmeter?
It's equally easy to make the graph too, you only have to try. Eclectic-tech is correct, you can do it with Shape meters, either Line or Path. Any program in the world, be it Excel, Google or Rainmeter draws graphs the same way, by using the formula Coordinate = Origin + Value * Unit, or derivatives like Coordinate = Origin + (Value / MaxValue) * Size, where everything bar the values is expressed in pixels. If you know how Excel works and follow the corresponding Shape syntax, you're definitely going to draw the desired graph. ;-)

I know, where is the example that you can modify? Here it is:

Code: Select all

[Variables]
AxisColorX=128,128,128,255
AxisColorY=128,128,128,255
GraphColor=255,0,0,255
StrokeWidth=1
MinValX=0
MaxValX=5
MinValY=0
MaxValY=5
OriginX=0
OriginY=100
UnitX=20
UnitY=20

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

---Measures---

[Value0]
Measure=Calc
Formula=3

[Value1]
Measure=Calc
Formula=4

[Value2]
Measure=Calc
Formula=1

[Value3]
Measure=Calc
Formula=2

[Value4]
Measure=Calc
Formula=0

[Value5]
Measure=Calc
Formula=5

---Meters---

[Back]
Meter=Image
W=(#UnitX#*(#MaxValX#-#MinValX#))
H=(#UnitY#*(#MaxValY#-#MinValY#))
SolidColor=0,0,0,128
DynamicVariables=1

[Graph]
Meter=Shape
Shape=Line (#OriginX#+#UnitX#*#MinValX#),(#OriginY#),(#OriginX#+#UnitX#*#MaxValX#),(#OriginY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorX#
Shape2=Line (#OriginX#),(#OriginY#-#UnitY#*#MinValY#),(#OriginX#),(#OriginY#-#UnitY#*#MaxValY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorY#
Shape3=Path Graph | StrokeWidth #StrokeWidth# | Stroke Color #GraphColor#
Graph=(#OriginX#+#UnitX#*(#MinValX#+0)),(#OriginY#-#UnitY#*[Value0]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+1)),(#OriginY#-#UnitY#*[Value1]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+2)),(#OriginY#-#UnitY#*[Value2]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+3)),(#OriginY#-#UnitY#*[Value3]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+4)),(#OriginY#-#UnitY#*[Value4]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+5)),(#OriginY#-#UnitY#*[Value5])
DynamicVariables=1
They're just 6 points, but I have no doubt you can add the rest. In your case, the Value measures would be the measures used to retrieve the cloud cover or the radiance from the open-meteo API, after adjusting the weather.com code earlier as advised. No MinValue or MaxValue options are needed in this version of the code. The style of the graph can be adjusted by altering the variables at the top of this code as desired.

Feel free to ask if you didn't understand something, we'd gladly help as long as you are willing to do the rest, since it's your skin and all. Or, you can wait for eclectic-tech to add such things in his skin, though that could take a while as there's no deadline involved (if he's interested in it, in the first place, since it involves quite a bit of work).

P.S. A possible (not sure how likely though) alternative to have the graph exactly as on the site's screenshot above (albeit probably without the mouse interactivity and hover capabilities) would be to look for ways to get / download the potential image(s) related to the graph, and display them on your skin. Yet another possibility would be to use that URL in a WebView measure, to display the page itself in the skin, like here (though that would have some drawbacks as mentioned there):
https://forum.rainmeter.net/viewtopic.php?t=43716&start=10#p222208
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
emp00
Posts: 83
Joined: October 7th, 2022, 8:08 pm

Re: WebParser XMLHttpRequest for weather forecast

Post by emp00 »

@Yincognito - Ok, challenge accepted :-) I have taken your example skins from above and adapted them as good as I could. Both the text output for 3 days (only precipitation [%] and irradiance [W/m2]) and both paramters are to be displayed as line graphs using your Shape line meter.

Unfortunately you're overestimating my RegExp skills. I know in principle what it does but I fail at adapting the RegExp to the Open-Meteo output. I have already changed the strings for finding my only two parameters ("precipitation_probability" and "global_tilted_irradiance") but a) the DPat/HPat patterns must be adapted somehow and b) OpenMeteo does only have a date/time-string but not the DayOfWeek in the api output. I'm sure the DayOfWeek can be calculated from the date with a smart calc measure, this would be great because I will need this information for the meter as well. To fix a) and b) I really need help...

See below the current complete code with comments and the WebParserDump.txt file that I use for skin development. Once the RegExp are working incl. DayOfWeek I think I can do the rest -> I will do my best. Really sorry for my bad coding skills and thanks for anybody's help on this.

:rosegift:

WebParserDump.txt (I have it in the skin directory)

Code: Select all

{"latitude":45.0,"longitude":12.0,"generationtime_ms":0.1659393310546875,"utc_offset_seconds":3600,"timezone":"Europe/Berlin","timezone_abbreviation":"CET","elevation":98.0,"hourly_units":{"time":"iso8601","precipitation_probability":"%","global_tilted_irradiance":"W/m²"},"hourly":{"time":["2024-03-17T00:00","2024-03-17T01:00","2024-03-17T02:00","2024-03-17T03:00","2024-03-17T04:00","2024-03-17T05:00","2024-03-17T06:00","2024-03-17T07:00","2024-03-17T08:00","2024-03-17T09:00","2024-03-17T10:00","2024-03-17T11:00","2024-03-17T12:00","2024-03-17T13:00","2024-03-17T14:00","2024-03-17T15:00","2024-03-17T16:00","2024-03-17T17:00","2024-03-17T18:00","2024-03-17T19:00","2024-03-17T20:00","2024-03-17T21:00","2024-03-17T22:00","2024-03-17T23:00","2024-03-18T00:00","2024-03-18T01:00","2024-03-18T02:00","2024-03-18T03:00","2024-03-18T04:00","2024-03-18T05:00","2024-03-18T06:00","2024-03-18T07:00","2024-03-18T08:00","2024-03-18T09:00","2024-03-18T10:00","2024-03-18T11:00","2024-03-18T12:00","2024-03-18T13:00","2024-03-18T14:00","2024-03-18T15:00","2024-03-18T16:00","2024-03-18T17:00","2024-03-18T18:00","2024-03-18T19:00","2024-03-18T20:00","2024-03-18T21:00","2024-03-18T22:00","2024-03-18T23:00","2024-03-19T00:00","2024-03-19T01:00","2024-03-19T02:00","2024-03-19T03:00","2024-03-19T04:00","2024-03-19T05:00","2024-03-19T06:00","2024-03-19T07:00","2024-03-19T08:00","2024-03-19T09:00","2024-03-19T10:00","2024-03-19T11:00","2024-03-19T12:00","2024-03-19T13:00","2024-03-19T14:00","2024-03-19T15:00","2024-03-19T16:00","2024-03-19T17:00","2024-03-19T18:00","2024-03-19T19:00","2024-03-19T20:00","2024-03-19T21:00","2024-03-19T22:00","2024-03-19T23:00","2024-03-20T00:00","2024-03-20T01:00","2024-03-20T02:00","2024-03-20T03:00","2024-03-20T04:00","2024-03-20T05:00","2024-03-20T06:00","2024-03-20T07:00","2024-03-20T08:00","2024-03-20T09:00","2024-03-20T10:00","2024-03-20T11:00","2024-03-20T12:00","2024-03-20T13:00","2024-03-20T14:00","2024-03-20T15:00","2024-03-20T16:00","2024-03-20T17:00","2024-03-20T18:00","2024-03-20T19:00","2024-03-20T20:00","2024-03-20T21:00","2024-03-20T22:00","2024-03-20T23:00","2024-03-21T00:00","2024-03-21T01:00","2024-03-21T02:00","2024-03-21T03:00","2024-03-21T04:00","2024-03-21T05:00","2024-03-21T06:00","2024-03-21T07:00","2024-03-21T08:00","2024-03-21T09:00","2024-03-21T10:00","2024-03-21T11:00","2024-03-21T12:00","2024-03-21T13:00","2024-03-21T14:00","2024-03-21T15:00","2024-03-21T16:00","2024-03-21T17:00","2024-03-21T18:00","2024-03-21T19:00","2024-03-21T20:00","2024-03-21T21:00","2024-03-21T22:00","2024-03-21T23:00","2024-03-22T00:00","2024-03-22T01:00","2024-03-22T02:00","2024-03-22T03:00","2024-03-22T04:00","2024-03-22T05:00","2024-03-22T06:00","2024-03-22T07:00","2024-03-22T08:00","2024-03-22T09:00","2024-03-22T10:00","2024-03-22T11:00","2024-03-22T12:00","2024-03-22T13:00","2024-03-22T14:00","2024-03-22T15:00","2024-03-22T16:00","2024-03-22T17:00","2024-03-22T18:00","2024-03-22T19:00","2024-03-22T20:00","2024-03-22T21:00","2024-03-22T22:00","2024-03-22T23:00","2024-03-23T00:00","2024-03-23T01:00","2024-03-23T02:00","2024-03-23T03:00","2024-03-23T04:00","2024-03-23T05:00","2024-03-23T06:00","2024-03-23T07:00","2024-03-23T08:00","2024-03-23T09:00","2024-03-23T10:00","2024-03-23T11:00","2024-03-23T12:00","2024-03-23T13:00","2024-03-23T14:00","2024-03-23T15:00","2024-03-23T16:00","2024-03-23T17:00","2024-03-23T18:00","2024-03-23T19:00","2024-03-23T20:00","2024-03-23T21:00","2024-03-23T22:00","2024-03-23T23:00"],"precipitation_probability":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,6,10,13,13,13,13,12,11,10,16,23,29,27,25,23,26,29,32,34,37,39,32,26,19,14,8,3,2,1,0,0,0,0,1,2,3,4,5,6,4,2,0,2,4,6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,2,1,0,1,2,3,3,3,3,3,3,3,3,3,3,3,3,3,5,8,10,8,5,3,3,3,3,2,1,0,1,2,3,8,14,19,19,19,19,17,15,13,13,13,13,19,26,32,36,41,45,45,45,45,45,45,45,40,34,29,32,36,39,44,50,55,54,53,52,46,41,35,27,18,10,10],"global_tilted_irradiance":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,3.7,112.1,320.1,394.9,406.2,611.9,512.2,311.6,272.4,214.4,156.3,55.0,5.6,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.9,16.7,55.7,116.0,105.2,111.0,110.6,122.3,100.4,112.2,105.6,49.3,6.5,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,4.6,72.4,230.7,494.9,506.7,517.8,676.9,553.1,411.5,305.0,163.1,53.8,8.4,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,6.5,60.3,169.8,395.2,644.0,796.5,822.0,725.1,549.7,366.5,197.1,71.1,16.8,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,8.3,76.1,206.8,349.6,472.0,556.5,566.9,485.7,359.3,241.3,137.2,57.6,12.1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,2.8,1.9,12.4,25.0,38.6,47.0,58.9,69.9,78.4,77.1,66.1,39.1,10.2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,22.3,113.1,254.5,403.1,508.1,567.7,569.5,518.2,422.5,303.8,175.9,62.1,16.0,0.0,0.0,0.0,0.0]}}
Open-Meteo-Weather-SolarIrradiance.ini

Code: Select all

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

; DPat = Day  Pattern (capture one 24 hour set from the current data field)
; HPat = Hour Pattern (capture each of the 24 hour values from current day)

[Variables]
; Variables for OpenMeteoAPI
; Demo sunny location in Italy
; https://api.open-meteo.com/v1/forecast?latitude=45.0&longitude=12.0&hourly=precipitation_probability,global_tilted_irradiance&timezone=Europe%2FBerlin&tilt=35&azimuth=-30
Lati=45.0
Longi=12.0
TimeZone=Europe%2FBerlin
PVTilt=35
PVAzimuth=-30
DPat=(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)
HPat=(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*)
; Variables for Line Graph: P=Precipitation, I=Irradiance
AxisColorX=128,128,128,255
AxisColorY=128,128,128,255
GraphColorP=255,0,0,255
GraphColorI=0,255,0,255
StrokeWidth=1
MinValX=0
MaxValX=5
MinValY=0
MaxValY=5
OriginX=0
OriginY=400
UnitX=20
UnitY=20


; Use the local file for frequent testing, and the online address once you finished the skin

[OpenMeteoAPI]
Measure=WebParser
;URL=https://api.open-meteo.com/v1/forecast?latitude=#Lati#&longitude=#Long#&hourly=precipitation_probability,global_tilted_irradiance&timezone=#TimeZone#&tilt=#PVTilt#&azimuth=#PVAzimuth#
URL=file://WebParserDump.txt
;When Debug=2 is used, WebParser will connect to the site, and download the HTML that is returned into WebParserDump.txt in the same folder with the skin .ini file. Once you have a copy of the site output in WebParserDump.txt, you should remove that Debug=2 option and save your skin.
UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36
RegExp=(?siU)\{"precipitation_probability":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"dayOfWeek":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"global_tilted_irradiance":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"time":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],
UpdateRate=600

; This only works for weather.com, needs to be adapted to open-meteo.com
; ================================================================
; StringIndex  = (Days * Field + Day)   <--   where Days = 15, Field = 0 to 3 = cloudCover to validTimeLocal, Day = 1 to 15
; StringIndex2 = Hour                   <--   where Hour = 1 to 24, from the current hour

; Example: Day 1 Hour 1

;[DayOfWeekD1H1]
; Commented out, not working for open-meteo.com, DayOfWeek must be calculated from date!
;Measure=WebParser
;URL=[OpenMeteoAPI]
;StringIndex=(15*1+1)
;RegExp=(?siU)#HPat#
;StringIndex2=1
;RegExpSubstitute=1
;Substitute='(?:^"|"$)':""

[mDateTimeD1H1]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*3+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mPrecipitationD1H1]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*0+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mIrradianceD1H1]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*2+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

; Example: Day 1 Hour 2

;[DayOfWeekD1H2]
; Commented out, not working for open-meteo.com, DayOfWeek must be calculated from date!
;Measure=WebParser
;URL=[OpenMeteoAPI]
;StringIndex=(15*1+1)
;RegExp=(?siU)#HPat#
;StringIndex2=2
;RegExpSubstitute=1
;Substitute='(?:^"|"$)':""

[mDateTimeD1H2]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*3+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mPrecipitationD1H2]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*0+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mIrradianceD1H2]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*2+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

; Example: Day 7 Hour 21

;[DayOfWeekD7H21]
; Commented out, not working for open-meteo.com, DayOfWeek must be calculated from date!
;Measure=WebParser
;URL=[OpenMeteoAPI]
;StringIndex=(15*1+7)
;RegExp=(?siU)#HPat#
;StringIndex2=21
;RegExpSubstitute=1
;Substitute='(?:^"|"$)':""

[mDateTimeD7H21]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*3+7)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mPrecipitationD7H21]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*0+7)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mIrradianceD7H21]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*2+7)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""


; Value Measures for Line Graph
; ##Precipitation##

[cPValue0]
; Precipitaton Graph Day1
Measure=Calc
Formula=mPrecipitationD1H1

[cPValue1]
; Precipitaton Graph Day1
Measure=Calc
Formula=mPrecipitationD1H2

[cPValue2]
; Precipitaton Graph DEMO for testing
Measure=Calc
Formula=5

[cPValue3]
; Precipitaton Graph DEMO for testing
Measure=Calc
Formula=3.2

[cPValue4]
; Precipitaton Graph DEMO for testing
Measure=Calc
Formula=1.3

[cPValue5]
; Precipitaton Graph D7H21 for testing
Measure=Calc
Formula=mPrecipitationD7H21 

; ##Irradiance##

[cIValue0]
; Irradiance Graph Day1
Measure=Calc
Formula=mIrradianceD1H1

[cIValue1]
; Irradiance Graph Day1
Measure=Calc
Formula=mIrradianceD1H2

[cIValue2]
; Irradiance Graph DEMO for testing
Measure=Calc
Formula=4

[cIValue3]
; Irradiance Graph DEMO for testing
Measure=Calc
Formula=2.5

[cIValue4]
; Irradiance Graph DEMO for testing
Measure=Calc
Formula=3.3

[cIValue5]
; Irradiance Graph D7H21 for testing
Measure=Calc
Formula=mIrradianceD7H21 

; ---Meters---

[Result]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
Padding=5,5,5,5
FontSize=12
AntiAlias=1
;MeasureName=mPrecipitationD1H1
;MeasureName2=DayOfWeekD1H1
;MeasureName3=mIrradianceD1H1
;MeasureName4=mDateTimeD1H1
;MeasureName5=mPrecipitationD1H2
;MeasureName6=DayOfWeekD1H2
;MeasureName7=mIrradianceD1H2
;MeasureName8=mDateTimeD1H2
;MeasureName9=mPrecipitationD7H21
;MeasureName10=DayOfWeekD7H21
;MeasureName11=mIrradianceD7H21
;MeasureName12=mDateTimeD7H21
;Text=Precipitation = %1%#CRLF#Day Of Week = %2#CRLF#Irradiance    = %3#CRLF#Date & Time = %4#CRLF##CRLF#Precipitation = %5%#CRLF#Day Of Week = %6#CRLF#Irradiation    = %7#CRLF#Date & Time = %8#CRLF##CRLF#Precipitation = %9%#CRLF#Day Of Week = %10#CRLF#Irradiance    = %11#CRLF#Date & Time = %12
Text=Date & Time   = [mDateTimeD1H1]#CRLF#Precipitation = [mPrecipitationD1H1]#CRLF#Irradiance    = [mIrradianceD1H1]#CRLF##CRLF#Date & Time   = [mDateTimeD1H2]#CRLF#Precipitation = [mPrecipitationD1H2]#CRLF#Irradiance    = [mIrradianceD1H2]#CRLF##CRLF#Date & Time   = [mDateTimeD7H21]#CRLF#Precipitation = [mPrecipitationD7H21]#CRLF#Irradiance    = [mIrradianceD7H21]#CRLF##CRLF#
DynamicVariables=1

; Meters for Line Graph Trend

[mGraphTrendBack]
Meter=Image
X=#OriginX#
Y=(#OriginY#-(#UnitY#*(#MaxValY#-#MinValY#)))
W=(#UnitX#*(#MaxValX#-#MinValX#))
H=(#UnitY#*(#MaxValY#-#MinValY#))
SolidColor=0,0,0,128
DynamicVariables=1

[mPrecipitationTrend]
; Precipitation = Red Line
Meter=Shape
Shape=Line (#OriginX#+#UnitX#*#MinValX#),(#OriginY#),(#OriginX#+#UnitX#*#MaxValX#),(#OriginY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorX#
Shape2=Line (#OriginX#),(#OriginY#-#UnitY#*#MinValY#),(#OriginX#),(#OriginY#-#UnitY#*#MaxValY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorY#
Shape3=Path Graph | StrokeWidth #StrokeWidth# | Stroke Color #GraphColorP#
Graph=(#OriginX#+#UnitX#*(#MinValX#+0)),(#OriginY#-#UnitY#*[cPValue0]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+1)),(#OriginY#-#UnitY#*[cPValue1]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+2)),(#OriginY#-#UnitY#*[cPValue2]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+3)),(#OriginY#-#UnitY#*[cPValue3]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+4)),(#OriginY#-#UnitY#*[cPValue4]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+5)),(#OriginY#-#UnitY#*[cPValue5])
DynamicVariables=1

[mIrradianceTrend]
; Irradiance = Green Line
Meter=Shape
Shape=Line (#OriginX#+#UnitX#*#MinValX#),(#OriginY#),(#OriginX#+#UnitX#*#MaxValX#),(#OriginY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorX#
Shape2=Line (#OriginX#),(#OriginY#-#UnitY#*#MinValY#),(#OriginX#),(#OriginY#-#UnitY#*#MaxValY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorY#
Shape3=Path Graph | StrokeWidth #StrokeWidth# | Stroke Color #GraphColorI#
Graph=(#OriginX#+#UnitX#*(#MinValX#+0)),(#OriginY#-#UnitY#*[cIValue0]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+1)),(#OriginY#-#UnitY#*[cIValue1]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+2)),(#OriginY#-#UnitY#*[cIValue2]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+3)),(#OriginY#-#UnitY#*[cIValue3]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+4)),(#OriginY#-#UnitY#*[cIValue4]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+5)),(#OriginY#-#UnitY#*[cIValue5])
DynamicVariables=1
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser XMLHttpRequest for weather forecast

Post by Yincognito »

emp00 wrote: March 17th, 2024, 1:20 pm @Yincognito - Ok, challenge accepted :-) I have taken your example skins from above and adapted them as good as I could. Both the text output for 3 days (only precipitation [%] and irradiance [W/m2]) and both paramters are to be displayed as line graphs using your Shape line meter.

Unfortunately you're overestimating my RegExp skills. I know in principle what it does but I fail at adapting the RegExp to the Open-Meteo output. I have already changed the strings for finding my only two parameters ("precipitation_probability" and "global_tilted_irradiance") but a) the DPat/HPat patterns must be adapted somehow and b) OpenMeteo does only have a date/time-string but not the DayOfWeek in the api output. I'm sure the DayOfWeek can be calculated from the date with a smart calc measure, this would be great because I will need this information for the meter as well. To fix a) and b) I really need help...

See below the current complete code with comments and the WebParserDump.txt file that I use for skin development. Once the RegExp are working incl. DayOfWeek I think I can do the rest -> I will do my best. Really sorry for my bad coding skills and thanks for anybody's help on this.

:rosegift:
Yeah, no worries, the important thing is that you're willing to try. :thumbup:

One problem in your implementation is the order of those field arrays (it's the arrays we're intrested in here, not necessarily the units; the latter are indeed present the order you used, but not the former): time is first, followed by precipitation and irradiance.

A related problem to this is that we have multiple occurrences of these field names (i.e. for units, for arrays, etc.), so we need to tell the parser to grab the parts related to the arrays, and not the units or else. This is easy in this case, we just need to precede the "time":\[ part of the regex with "hourly":\{ taking into account that literal brackets need to be escaped in regex by preceding them with the \ symbol. So, bar the .* stuff, we simply replicate how the original string looks like, being careful to choose unique occurrences in the string, as much as possible (that's again simple, since we don't have another hourly part in the string that looks exactly like this one).

Another problem is that you still use 15 #DPat# instances in your regex. Didn't count, but based on your earlier screenshot, your open-meteo API query retrieves only 7 days of data, hence using just 7 #DPat# instances for all arrays would most likely correct that in your case.

Again, related to the above, you should use corresponding StringIndex values in the other WebParser measures, based on the only 7 days of data and only 3 fields to be retrieved (time, precipitation and irradiance), according to the formulas in the comments.

If the above is done correctly, the measures should start having the right values, something you can easily see in the About > Skins tab, aka the Rainmeter log. As a result, the graph should start placing the points properly - although you should set the graph variables to permit the whole range of values and with a suited unit (see the Min, Max and Unit variables).

So, try the above and let us know of the result. Right now I'm on my phone so can't test and such, but later on when I get back to my laptop I'll be able to work with code as well, if by any chance you don't make progress till then. You should try to do that though, since many times doing things yourself is the best way to learn, and too much assistance can often lead the one being helped not being able to replicate things in another similar situation. We'll be here to help out if you stumble anyway. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
emp00
Posts: 83
Joined: October 7th, 2022, 8:08 pm

Re: WebParser XMLHttpRequest for weather forecast

Post by emp00 »

Thanks for the patience. I understand what you're explaining - indeed I only have 7 days und thus I shortened the initial RegExp occurrences of #DPat# accordingly. Also I am starting matching in this order trying to catch time, precipitation and irradiance: "hourly":\{"time":\[ - .*"precipitation_probability":\ - .*"global_tilted_irradiance":\[

My complete RegExp in the WebParser measure [OpenMeteoAPI] now is this:

Code: Select all

RegExp=(?siU)\{"hourly":\{"time":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"precipitation_probability":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"global_tilted_irradiance":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],
Result :-(
RegExp matching error (-1) (Open-Meteo-Weather_MK\Open-Meteo-Weather-SolarIrradiance.ini - [OpenMeteoAPI])

I know that "every character counts" in RegExp but for me this is quite frustrating "poking in the dark"... I tried to move the expressions into the correct order and changed the "time" matching pattern exactly as you mentioned. The error message does not give me any clue where exactly the RegExp fails and looking into the skin variables does not help since my variables in question are all "0" because the initial RexExp failed.

I even used RainRegExp.exe to find my error but here, well the #DPat# variable does not exist, so I needed to search/replace this (done) getting a superlong string and then I still only got the same error message. No hint what's the problem.

How would I set up a working RegExp efficiently "from scratch" in this case? I only did that in the past once with a very "simple" case compared to this and also this was a hours of work "try&error" for me to get it running. How are you guys doing this in such a case? My last hope would be asking ChatGPT but, well, no. I give up :-(

I know you're laughing experts, but really for me it's a needle-in-the-haystack-job. Thanks for looking into this, I feel very bad.

Complete non-working code (I have not yet changed the StringIndex values, first the initial RegExp needs to be working, right?):

Code: Select all

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

; DPat = Day  Pattern (capture one 24 hour set from the current data field)
; HPat = Hour Pattern (capture each of the 24 hour values from current day)

[Variables]
; Variables for OpenMeteoAPI
;Demo sunny location in Italy
;https://api.open-meteo.com/v1/forecast?latitude=45.0&longitude=12.0&hourly=precipitation_probability,global_tilted_irradiance&timezone=Europe%2FBerlin&tilt=35&azimuth=-30
Lati=45.0
Longi=12.0
TimeZone=Europe%2FBerlin
PVTilt=35
PVAzimuth=-30
DPat=(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)
HPat=(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*)
; Variables for Line Graph: P=Precipitation, I=Irradiance
AxisColorX=128,128,128,255
AxisColorY=128,128,128,255
GraphColorP=255,0,0,255
GraphColorI=0,255,0,255
StrokeWidth=1
MinValX=0
MaxValX=5
MinValY=0
MaxValY=5
OriginX=0
OriginY=400
UnitX=20
UnitY=20


; Use the local file for frequent testing, and the online address once you finished the skin

[OpenMeteoAPI]
Measure=WebParser
;URL=https://api.open-meteo.com/v1/forecast?latitude=#Lati#&longitude=#Long#&hourly=precipitation_probability,global_tilted_irradiance&timezone=#TimeZone#&tilt=#PVTilt#&azimuth=#PVAzimuth#
URL=file://#CURRENTPATH#WebParserDump.txt
;When Debug=2 is used, WebParser will connect to the site, and download the HTML that is returned into WebParserDump.txt in the same folder with the skin .ini file. Once you have a copy of the site output in WebParserDump.txt, you should remove that Debug=2 option and save your skin.
UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36
RegExp=(?siU)\{"hourly":\{"time":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"precipitation_probability":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"global_tilted_irradiance":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],
UpdateRate=600

; StringIndex  = (Days * Field + Day)   <--   where Days = 15, Field = 0 to 3 = cloudCover to validTimeLocal, Day = 1 to 15
; StringIndex2 = Hour                   <--   where Hour = 1 to 24, from the current hour

; Example: Day 1 Hour 1

;[DayOfWeekD1H1]
;Measure=WebParser
;URL=[OpenMeteoAPI]
;StringIndex=(15*1+1)
;RegExp=(?siU)#HPat#
;StringIndex2=1
;RegExpSubstitute=1
;Substitute='(?:^"|"$)':""

[mDateTimeD1H1]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*3+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mPrecipitationD1H1]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*0+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mIrradianceD1H1]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*2+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

; Example: Day 1 Hour 2

;[DayOfWeekD1H2]
;Measure=WebParser
;URL=[OpenMeteoAPI]
;StringIndex=(15*1+1)
;RegExp=(?siU)#HPat#
;StringIndex2=2
;RegExpSubstitute=1
;Substitute='(?:^"|"$)':""

[mDateTimeD1H2]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*3+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mPrecipitationD1H2]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*0+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mIrradianceD1H2]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*2+1)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

; Example: Day 7 Hour 21

;[DayOfWeekD7H21]
;Measure=WebParser
;URL=[OpenMeteoAPI]
;StringIndex=(15*1+7)
;RegExp=(?siU)#HPat#
;StringIndex2=21
;RegExpSubstitute=1
;Substitute='(?:^"|"$)':""

[mDateTimeD7H21]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*3+7)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mPrecipitationD7H21]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*0+7)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""

[mIrradianceD7H21]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(15*2+7)
RegExp=(?siU)#HPat#
StringIndex2=21
RegExpSubstitute=1
Substitute='(?:^"|"$)':""


; Value Measures for Line Graph
; ##Precipitation##

[cPValue0]
; Precipitaton Graph Day1
Measure=Calc
Formula=mPrecipitationD1H1

[cPValue1]
; Precipitaton Graph Day1
Measure=Calc
Formula=mPrecipitationD1H2

[cPValue2]
; Precipitaton Graph DEMO for testing
Measure=Calc
Formula=5

[cPValue3]
; Precipitaton Graph DEMO for testing
Measure=Calc
Formula=3.2

[cPValue4]
; Precipitaton Graph DEMO for testing
Measure=Calc
Formula=1.3

[cPValue5]
; Precipitaton Graph D7H21 for testing
Measure=Calc
Formula=mPrecipitationD7H21 

; ##Irradiance##

[cIValue0]
; Irradiance Graph Day1
Measure=Calc
Formula=mIrradianceD1H1

[cIValue1]
; Irradiance Graph Day1
Measure=Calc
Formula=mIrradianceD1H2

[cIValue2]
; Irradiance Graph DEMO for testing
Measure=Calc
Formula=4

[cIValue3]
; Irradiance Graph DEMO for testing
Measure=Calc
Formula=2.5

[cIValue4]
; Irradiance Graph DEMO for testing
Measure=Calc
Formula=3.3

[cIValue5]
; Irradiance Graph D7H21 for testing
Measure=Calc
Formula=mIrradianceD7H21 

; ---Meters---

[Result]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
Padding=5,5,5,5
FontSize=12
AntiAlias=1
;MeasureName=mPrecipitationD1H1
;MeasureName2=DayOfWeekD1H1
;MeasureName3=mIrradianceD1H1
;MeasureName4=mDateTimeD1H1
;MeasureName5=mPrecipitationD1H2
;MeasureName6=DayOfWeekD1H2
;MeasureName7=mIrradianceD1H2
;MeasureName8=mDateTimeD1H2
;MeasureName9=mPrecipitationD7H21
;MeasureName10=DayOfWeekD7H21
;MeasureName11=mIrradianceD7H21
;MeasureName12=mDateTimeD7H21
;Text=Precipitation = %1%#CRLF#Day Of Week = %2#CRLF#Irradiance    = %3#CRLF#Date & Time = %4#CRLF##CRLF#Precipitation = %5%#CRLF#Day Of Week = %6#CRLF#Irradiation    = %7#CRLF#Date & Time = %8#CRLF##CRLF#Precipitation = %9%#CRLF#Day Of Week = %10#CRLF#Irradiance    = %11#CRLF#Date & Time = %12
Text=Date & Time   = [mDateTimeD1H1]#CRLF#Precipitation = [mPrecipitationD1H1]#CRLF#Irradiance    = [mIrradianceD1H1]#CRLF##CRLF#Date & Time   = [mDateTimeD1H2]#CRLF#Precipitation = [mPrecipitationD1H2]#CRLF#Irradiance    = [mIrradianceD1H2]#CRLF##CRLF#Date & Time   = [mDateTimeD7H21]#CRLF#Precipitation = [mPrecipitationD7H21]#CRLF#Irradiance    = [mIrradianceD7H21]#CRLF##CRLF#
DynamicVariables=1

; Meters for Line Graph Trend

[mGraphTrendBack]
Meter=Image
X=#OriginX#
Y=(#OriginY#-(#UnitY#*(#MaxValY#-#MinValY#)))
W=(#UnitX#*(#MaxValX#-#MinValX#))
H=(#UnitY#*(#MaxValY#-#MinValY#))
SolidColor=0,0,0,128
DynamicVariables=1

[mPrecipitationTrend]
Meter=Shape
Shape=Line (#OriginX#+#UnitX#*#MinValX#),(#OriginY#),(#OriginX#+#UnitX#*#MaxValX#),(#OriginY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorX#
Shape2=Line (#OriginX#),(#OriginY#-#UnitY#*#MinValY#),(#OriginX#),(#OriginY#-#UnitY#*#MaxValY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorY#
Shape3=Path Graph | StrokeWidth #StrokeWidth# | Stroke Color #GraphColorP#
Graph=(#OriginX#+#UnitX#*(#MinValX#+0)),(#OriginY#-#UnitY#*[cPValue0]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+1)),(#OriginY#-#UnitY#*[cPValue1]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+2)),(#OriginY#-#UnitY#*[cPValue2]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+3)),(#OriginY#-#UnitY#*[cPValue3]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+4)),(#OriginY#-#UnitY#*[cPValue4]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+5)),(#OriginY#-#UnitY#*[cPValue5])
DynamicVariables=1

[mIrradianceTrend]
Meter=Shape
Shape=Line (#OriginX#+#UnitX#*#MinValX#),(#OriginY#),(#OriginX#+#UnitX#*#MaxValX#),(#OriginY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorX#
Shape2=Line (#OriginX#),(#OriginY#-#UnitY#*#MinValY#),(#OriginX#),(#OriginY#-#UnitY#*#MaxValY#) | StrokeWidth #StrokeWidth# | Stroke Color #AxisColorY#
Shape3=Path Graph | StrokeWidth #StrokeWidth# | Stroke Color #GraphColorI#
Graph=(#OriginX#+#UnitX#*(#MinValX#+0)),(#OriginY#-#UnitY#*[cIValue0]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+1)),(#OriginY#-#UnitY#*[cIValue1]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+2)),(#OriginY#-#UnitY#*[cIValue2]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+3)),(#OriginY#-#UnitY#*[cIValue3]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+4)),(#OriginY#-#UnitY#*[cIValue4]) | LineTo (#OriginX#+#UnitX#*(#MinValX#+5)),(#OriginY#-#UnitY#*[cIValue5])
DynamicVariables=1
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser XMLHttpRequest for weather forecast

Post by Yincognito »

emp00 wrote: March 17th, 2024, 5:52 pm I know you're laughing experts [...] I feel very bad.
Stop this nonsense, nobody is laughing at you, and you don't have to feel bad. Period. And in general, even if somebody would, chin up, be confident, positive, don't care about the objections of naysayers, and remember that everything has at least one solution and nothing is impossible as long as you really want it. Relax when tired, never give up, and keep in mind that understanding how stuff goes is the only thing one needs to do something - the rest, the resources, the execution, the optimization, are just secondary details that can be achieved and perfected in time.
emp00 wrote: March 17th, 2024, 5:52 pm How would I set up a working RegExp efficiently "from scratch" in this case?
I already told you, try it on either RegExr.com or regex101.com. Forget about ChatGPT or RainRegExp. They are well done and useful for basic things, but they're limited and cannot replace a comprehensive testing ground and your own mind - with the latter being your greatest asset. This is how I approach things, if both StringIndex and StringIndex2 are involved (for a Substitute, I use a similar approach, see the Replace button on those pages) - by the way, you don't necessarily have to use the whole things, you can simplify and use what you're interested in (but yeah, variables will have to be replaced, a matter of basic CTRL+A, CTRL+C, CTRL+V and the like). Don't forget to choose PCRE as the regex flavor from the button at top right on these pages, and check the RegEx Reference from the sidebar on the left side for info on what various symbols mean...

1st tab
RegExR.com - StringIndex.jpg
- Expression: the main RegExp

Code: Select all

(?siU)"hourly":\{"time":\[(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)\],.*"precipitation_probability":\[(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)\],.*"global_tilted_irradiance":\[(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*),(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)\]
- Text: the WebParserDump.txt

Code: Select all

{"latitude":45.0,"longitude":12.0,"generationtime_ms":0.1659393310546875,"utc_offset_seconds":3600,"timezone":"Europe/Berlin","timezone_abbreviation":"CET","elevation":98.0,"hourly_units":{"time":"iso8601","precipitation_probability":"%","global_tilted_irradiance":"W/m²"},"hourly":{"time":["2024-03-17T00:00","2024-03-17T01:00","2024-03-17T02:00","2024-03-17T03:00","2024-03-17T04:00","2024-03-17T05:00","2024-03-17T06:00","2024-03-17T07:00","2024-03-17T08:00","2024-03-17T09:00","2024-03-17T10:00","2024-03-17T11:00","2024-03-17T12:00","2024-03-17T13:00","2024-03-17T14:00","2024-03-17T15:00","2024-03-17T16:00","2024-03-17T17:00","2024-03-17T18:00","2024-03-17T19:00","2024-03-17T20:00","2024-03-17T21:00","2024-03-17T22:00","2024-03-17T23:00","2024-03-18T00:00","2024-03-18T01:00","2024-03-18T02:00","2024-03-18T03:00","2024-03-18T04:00","2024-03-18T05:00","2024-03-18T06:00","2024-03-18T07:00","2024-03-18T08:00","2024-03-18T09:00","2024-03-18T10:00","2024-03-18T11:00","2024-03-18T12:00","2024-03-18T13:00","2024-03-18T14:00","2024-03-18T15:00","2024-03-18T16:00","2024-03-18T17:00","2024-03-18T18:00","2024-03-18T19:00","2024-03-18T20:00","2024-03-18T21:00","2024-03-18T22:00","2024-03-18T23:00","2024-03-19T00:00","2024-03-19T01:00","2024-03-19T02:00","2024-03-19T03:00","2024-03-19T04:00","2024-03-19T05:00","2024-03-19T06:00","2024-03-19T07:00","2024-03-19T08:00","2024-03-19T09:00","2024-03-19T10:00","2024-03-19T11:00","2024-03-19T12:00","2024-03-19T13:00","2024-03-19T14:00","2024-03-19T15:00","2024-03-19T16:00","2024-03-19T17:00","2024-03-19T18:00","2024-03-19T19:00","2024-03-19T20:00","2024-03-19T21:00","2024-03-19T22:00","2024-03-19T23:00","2024-03-20T00:00","2024-03-20T01:00","2024-03-20T02:00","2024-03-20T03:00","2024-03-20T04:00","2024-03-20T05:00","2024-03-20T06:00","2024-03-20T07:00","2024-03-20T08:00","2024-03-20T09:00","2024-03-20T10:00","2024-03-20T11:00","2024-03-20T12:00","2024-03-20T13:00","2024-03-20T14:00","2024-03-20T15:00","2024-03-20T16:00","2024-03-20T17:00","2024-03-20T18:00","2024-03-20T19:00","2024-03-20T20:00","2024-03-20T21:00","2024-03-20T22:00","2024-03-20T23:00","2024-03-21T00:00","2024-03-21T01:00","2024-03-21T02:00","2024-03-21T03:00","2024-03-21T04:00","2024-03-21T05:00","2024-03-21T06:00","2024-03-21T07:00","2024-03-21T08:00","2024-03-21T09:00","2024-03-21T10:00","2024-03-21T11:00","2024-03-21T12:00","2024-03-21T13:00","2024-03-21T14:00","2024-03-21T15:00","2024-03-21T16:00","2024-03-21T17:00","2024-03-21T18:00","2024-03-21T19:00","2024-03-21T20:00","2024-03-21T21:00","2024-03-21T22:00","2024-03-21T23:00","2024-03-22T00:00","2024-03-22T01:00","2024-03-22T02:00","2024-03-22T03:00","2024-03-22T04:00","2024-03-22T05:00","2024-03-22T06:00","2024-03-22T07:00","2024-03-22T08:00","2024-03-22T09:00","2024-03-22T10:00","2024-03-22T11:00","2024-03-22T12:00","2024-03-22T13:00","2024-03-22T14:00","2024-03-22T15:00","2024-03-22T16:00","2024-03-22T17:00","2024-03-22T18:00","2024-03-22T19:00","2024-03-22T20:00","2024-03-22T21:00","2024-03-22T22:00","2024-03-22T23:00","2024-03-23T00:00","2024-03-23T01:00","2024-03-23T02:00","2024-03-23T03:00","2024-03-23T04:00","2024-03-23T05:00","2024-03-23T06:00","2024-03-23T07:00","2024-03-23T08:00","2024-03-23T09:00","2024-03-23T10:00","2024-03-23T11:00","2024-03-23T12:00","2024-03-23T13:00","2024-03-23T14:00","2024-03-23T15:00","2024-03-23T16:00","2024-03-23T17:00","2024-03-23T18:00","2024-03-23T19:00","2024-03-23T20:00","2024-03-23T21:00","2024-03-23T22:00","2024-03-23T23:00"],"precipitation_probability":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,6,10,13,13,13,13,12,11,10,16,23,29,27,25,23,26,29,32,34,37,39,32,26,19,14,8,3,2,1,0,0,0,0,1,2,3,4,5,6,4,2,0,2,4,6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,2,1,0,1,2,3,3,3,3,3,3,3,3,3,3,3,3,3,5,8,10,8,5,3,3,3,3,2,1,0,1,2,3,8,14,19,19,19,19,17,15,13,13,13,13,19,26,32,36,41,45,45,45,45,45,45,45,40,34,29,32,36,39,44,50,55,54,53,52,46,41,35,27,18,10,10],"global_tilted_irradiance":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,3.7,112.1,320.1,394.9,406.2,611.9,512.2,311.6,272.4,214.4,156.3,55.0,5.6,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.9,16.7,55.7,116.0,105.2,111.0,110.6,122.3,100.4,112.2,105.6,49.3,6.5,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,4.6,72.4,230.7,494.9,506.7,517.8,676.9,553.1,411.5,305.0,163.1,53.8,8.4,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,6.5,60.3,169.8,395.2,644.0,796.5,822.0,725.1,549.7,366.5,197.1,71.1,16.8,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,8.3,76.1,206.8,349.6,472.0,556.5,566.9,485.7,359.3,241.3,137.2,57.6,12.1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,2.8,1.9,12.4,25.0,38.6,47.0,58.9,69.9,78.4,77.1,66.1,39.1,10.2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,22.3,113.1,254.5,403.1,508.1,567.7,569.5,518.2,422.5,303.8,175.9,62.1,16.0,0.0,0.0,0.0,0.0]}}
- Tools: the capture to be retrieved, from \1 to \N where N is the number of captures (i.e. stuff enclosed between unescaped ( and ) round brackets)

Code: Select all

\1
2nd tab
RegExR.com - StringIndex2.jpg
- Expression: the RegExp from StringIndex2 measures (added ^ and $ aka the start and end of the string to properly capture the 24th value with the ?U flag)

Code: Select all

(?siU)^(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*)$
- Text: the result of the 1st tab

Code: Select all

"2024-03-17T00:00","2024-03-17T01:00","2024-03-17T02:00","2024-03-17T03:00","2024-03-17T04:00","2024-03-17T05:00","2024-03-17T06:00","2024-03-17T07:00","2024-03-17T08:00","2024-03-17T09:00","2024-03-17T10:00","2024-03-17T11:00","2024-03-17T12:00","2024-03-17T13:00","2024-03-17T14:00","2024-03-17T15:00","2024-03-17T16:00","2024-03-17T17:00","2024-03-17T18:00","2024-03-17T19:00","2024-03-17T20:00","2024-03-17T21:00","2024-03-17T22:00","2024-03-17T23:00"
- Tools: the capture to be retrieved, aka the value of StringIndex2 in such a measure, preceded by \ (which is how you reference a capture)

Code: Select all

\1
emp00 wrote: March 17th, 2024, 5:52 pm I know that "every character counts" in RegExp
first the initial RegExp needs to be working, right?
Precisely - you got the idea. The thing is, like you probably noticed above, there is no { right before "hourly":[, and there is also no , after the last ] in the string, like you had in your version of the main RegExp. This is why your otherwise correct regex failed. The devil is in the details, right? :D

So, I adjusted the code as already described, simplified it, removed some stuff, changed a few things here and there for convenience:

Code: Select all

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

[Variables]
Lati=45.0
Long=12.0
TimeZone=Europe%2FBerlin
PVTilt=35
PVAzimuth=-30
DPat=(.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)
HPat=^(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*)$
BackColor=0,0,0,128
EdgeColor=0,0,255,255
AxisColorX=128,128,128,255
AxisColorY=128,128,128,255
GraphColorP=255,0,0,255
GraphColorI=0,255,0,255
SW=1
MinValX=0
MaxValX=168
MinValY=0
MaxValY=750
OriginX=0
OriginY=168
UnitX=2
UnitY=0.224

---Measures---

[OpenMeteoAPI]
Measure=WebParser
;URL=https://api.open-meteo.com/v1/forecast?latitude=#Lati#&longitude=#Long#&hourly=precipitation_probability,global_tilted_irradiance&timezone=#TimeZone#&tilt=#PVTilt#&azimuth=#PVAzimuth#
URL=file://#CURRENTPATH#WebParserDump.txt
UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36
RegExp=(?siU)"hourly":\{"time":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"precipitation_probability":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\],.*"global_tilted_irradiance":\[#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#,#DPat#\]
UpdateRate=600

; StringIndex  = (Days * Field + Day)   <--   where Days = 7, Field = 0 to 2 = time to global_tilted_irradiance, Day = 1 to 7
; StringIndex2 = Hour                   <--   where Hour = 1 to 24, from the hour when the request was made to the site's API

; Day 1, Hour 1

[mTimeD1H1]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(7*0+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':"","^$":"0000-00-00T00:00"
DynamicVariables=1

[mPrecD1H1]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(7*1+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':"","^$":"0"

[mIrraD1H1]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(7*2+1)
RegExp=(?siU)#HPat#
StringIndex2=1
RegExpSubstitute=1
Substitute='(?:^"|"$)':"","^$":"0"

; Day 2, Hour 2

[mTimeD1H2]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(7*0+2)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':"","^$":"0000-00-00T00:00"

[mPrecD1H2]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(7*1+2)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':"","^$":"0"

[mIrraD1H2]
Measure=WebParser
URL=[OpenMeteoAPI]
StringIndex=(7*2+2)
RegExp=(?siU)#HPat#
StringIndex2=2
RegExpSubstitute=1
Substitute='(?:^"|"$)':"","^$":"0"

---Meters---

[Trends]
Meter=Shape
Shape=Rectangle (#SW#/2),(#SW#/2),(#UnitX#*(#MaxValX#-#MinValX#)),(#UnitY#*(#MaxValY#-#MinValY#)) | StrokeWidth #SW# | Stroke Color #EdgeColor# | Fill Color #BackColor#
Shape2=Line (#OriginX#+#UnitX#*#MinValX#+#SW#/2),(#OriginY#+#SW#/2),(#OriginX#+#UnitX#*#MaxValX#+#SW#/2),(#OriginY#+#SW#/2) | StrokeWidth #SW# | Stroke Color #AxisColorX#
Shape3=Line (#OriginX#+#SW#/2),(#OriginY#-#UnitY#*#MinValY#+#SW#/2),(#OriginX#+#SW#/2),(#OriginY#-#UnitY#*#MaxValY#+#SW#/2) | StrokeWidth #SW# | Stroke Color #AxisColorY#
Shape4=Path PGraph | StrokeWidth #SW# | Stroke Color #GraphColorP#
PGraph=(#OriginX#+#UnitX#*(#MinValX#+0)+#SW#/2),(#OriginY#-#UnitY#*[mPrecD1H1]+#SW#/2) | LineTo (#OriginX#+#UnitX#*(#MinValX#+1)+#SW#/2),(#OriginY#-#UnitY#*[mPrecD1H2]+#SW#/2)
Shape5=Path IGraph | StrokeWidth #SW# | Stroke Color #GraphColorI#
IGraph=(#OriginX#+#UnitX#*(#MinValX#+0)+#SW#/2),(#OriginY#-#UnitY#*[mIrraD1H1]+#SW#/2) | LineTo (#OriginX#+#UnitX#*(#MinValX#+1)+#SW#/2),(#OriginY#-#UnitY#*[mIrraD1H2]+#SW#/2)
DynamicVariables=1
And the result (you can notice the graphs started to be drawn if you carefully look at the bottom left corner or you magnify the image):
Graph.png
By the way, I used the MaxValY of 750 from your site screenshot, a MaxValX of 24 * 7 = 168, UnitX is 2 so the graph is 168 * 2 = 336 pixels wide and UnitY is 0.224 aka 168 / 750 so that the graph is 168 pixels in height. Feel free to adjust these things to your preference, if you want something else. What's left to do is just copy paste the rest of the 3 WebParser measure sets (StringIndex and StringIndex2 based on the updated formulas), and add corresponding | Line ... parts to PGraph and IGraph. It's a lengthy process (shorter if smartly using the regex Replace capabilities of Notepad++, although you'd end up with a 5076 lines skin!), but not complicated. If you wonder, I had to add #SW#/2 to all coordinates because of the note here:
https://docs.rainmeter.net/manual/meters/shape/#StrokeWidth
One other thing, if you want the precipitation points / graph to be as "tall" as the irradiance one, just multiply the #UnitY# instances from PGraph with a suitable value (I'd say with 6, so that the Y=125 for precipitation points is at the same level as the Y=750 for irradiance points, like in the screenshot - since 750 / 125 is 6 and such). For conveniency, you could define some UnitFactorP=6 and UnitFactorI=1 variables in [Variables], then just replace every #UnitY# with #UnitY#*#UnitFactorP# and #UnitY#*#UnitFactorI# in PGraph and IGraph, respectively.

Good luck adding more to the skin, if desired. If you have any other questions, just ask. ;-)

P.S. I only used Day 2 Hour 2 as the second set of 3 measures above because it had a non zero value for precipitations, to showcase that the graph works. Feel free to use (7*0+1), (7*1+1), (7*2+1) as the values of those measures' StringIndex, to get Day 1 Hour 2 instead.
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
emp00
Posts: 83
Joined: October 7th, 2022, 8:08 pm

Re: WebParser XMLHttpRequest for weather forecast

Post by emp00 »

Yincognito wrote: March 17th, 2024, 9:26 pm I already told you, try it on either RegExr.com or regex101.com. Forget about ChatGPT or RainRegExp. [...]
:thumbup: I am missing words, all I can say today is THANK YOU !

Promised, I will go through your excellent step-by-step intro using RegExr.com. I am not sure, if you already told me to use RegExr or regex101, I must have missed it. Sorry for that! Since I'm a working person "5 days-a-week", I will now reserve a few hours time next weekend to go through your posting. I promise, I will not just copy/paste your (probably close-to-finished) script but will try to understand how to do it myself for future projects (I already have ideas what to do next - all based on OpenMeteo weather data, so I am surely gonna need more RegExp expertise for that). Such detailed guidance is exactly what I need to be able to understand. Practical guidance - very, very well done! Thanks for the time you took for that, much appreciated.

Yesterday I was indeed really frustrated - next weekend I'm gonna make it! Nothing's impossible. Chapeau, Yincognito!