It is currently July 27th, 2024, 2:42 am

Weather skin RegEx error.

Get help with creating, editing & fixing problems with skins
User avatar
sl23
Posts: 1451
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Weather skin RegEx error.

Post by sl23 »

It's been working for around 2-3 years now, but all of a sudden it's stopped showing the current temperature and looking at the log I have two errors:
1. Just says "Something Went Wrong"
2. RegExp matching error (-1) (RM\Weather\Weather.ini - [mWeatherParent])

I haven't changed anything and I have no knowledge of how RegEx works. Would somebody please tell me what's happened and how to fix? Thank you so much.

Here's the code in two separate files:
Weather.ini
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,1
OnRefreshAction=[!UpdateMeter *] [!UpdateMeter *] [!Redraw]
@Include=WeatherParser.inc

[Metadata]
Name=Weather
Author=sl23
Version=2023-09-18
License=Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
Information=Adapted from JDWS-04 by Jelle Dekkers (github.com/adriaanjelle)

[Variables]
Green=128,255,0
White=255,255,255,200

WeatherLocation=**********
; Just enter your city's name or your address here or whatever. Anything should work here.
; TIP: Check Rainmeter's About/log to see what location it got.

========================================
; STYLES
========================================
[Style]
FontFace=Trebuchet MS
FontColor=#White#
FontSize=12
AntiAlias=1
DynamicVariables=1
UpdateDivider=-1

[sHighlight]
MouseOverAction=[!SetOption #CURRENTSECTION# FontColor "#Green#"] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# FontColor ""] [!UpdateMeter #CURRENTSECTION#] [!Redraw]

========================================
; WEATHER
========================================
[WeatherCurrentTemperature]
Meter=String
MeterStyle=Style | sHighlight
Text=[mWeatherCurrentTemperature]°
LeftMouseUpAction=[!Refresh]
MiddleMouseUpAction=[!EditSkin]
ToolTipIcon=Info
ToolTipTitle=[mWeatherLocationCity]
ToolTipText=L - Refresh#CRLF#M - Set Location
X=2
Y=0
WeatherParser.ini
[Variables]
Language=en-GB
WeatherAPIKey=21d8a80b3d6b444998a80b3d6b1449d3
WeatherUnitsMetric=m
WeatherUnitsImperial=e
WeatherRegExpString=((?(?=null)null|".*"))
WeatherRegExpNumber=((?(?=null)null|.*))
WeatherSubstitute="^null$":"", '^"(.*)"$':"\1", "^\\1$":""
WeatherUnits=Metric
; The units of the weather info. Valid values are "Metric" and "Imperial".

[mInternetConnectivity]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
OnChangeAction=[!CommandMeasure mWeatherLocationParent Update]

; ================================================

[mWeatherLocationParent]
Measure=WebParser
URL=https://nominatim.openstreetmap.org/search?q=#WeatherLocation#&format=geocodejson&limit=1&addressdetails=1
RegExp=(?siU)"features":\[{"type":"Feature","properties":{"geocoding":{.*,"label":"(.*)",.*,"admin":{"level\d+":"(.*)".*}}},"geometry":{"type": "Point","coordinates": \[(.*), (.*)\]}}\]
UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36
UpdateRate=(60*15)

FinishAction=[!UpdateMeasureGroup WeatherLocation] [!EnableMeasure mWeatherParent] [!UpdateMeasure mWeatherParent] [!Log "Location found: [mWeatherLocation]" Notice]
OnConnectErrorAction=[!UpdateMeasureGroup WeatherLocation] [!EnableMeasure mWeatherParent] [!UpdateMeasure mWeatherParent] [!Log "Unable to connect to Nominatim." Error]
OnRegExpErrorAction=[!UpdateMeasureGroup WeatherLocation] [!EnableMeasure mWeatherParent] [!UpdateMeasure mWeatherParent] [!Log "No results found for that location." Error]

; ================================================

[mWeatherLocation]
Group=WeatherLocation
Measure=WebParser
URL=[mWeatherLocationParent]
StringIndex=1

[mWeatherLocationCity]
Group=WeatherLocation
Measure=WebParser
URL=[mWeatherLocationParent]
StringIndex=2
Substitute="":"Earth"

[mWeatherLocationLat]
Group=WeatherLocation
Measure=WebParser
URL=[mWeatherLocationParent]
StringIndex=4
Substitute="":"None"

[mWeatherLocationLon]
Group=WeatherLocation
Measure=WebParser
URL=[mWeatherLocationParent]
StringIndex=3
Substitute="":"None"

; ================================================

[mWeatherParent]
Group=Parent
Measure=WebParser

URL=https://api.weather.com/v3/aggcommon/v3-wx-observations-current;v3-wx-forecast-daily-15day?format=json&geocode=[&mWeatherLocationLat],[&mWeatherLocationLon]&units=[#WeatherUnits[#WeatherUnits]]&language=[#Language]&apiKey=#WeatherAPIKey#
RegExp=(?siU)"v3-wx-observations-current":.*{(.*)}.*"v3-wx-forecast-daily-15day":.*{(.*),"daypart":\[{(.*)}\]}
UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36
UpdateRate=1

FinishAction=[!EnableMeasureGroup Weather] [!UpdateMeasureGroup Weather] [!UpdateMeter *] [!UpdateMeter *] [!Redraw] [!Log "Finished parsing weather data." Notice]
OnConnectErrorAction=[!EnableMeasureGroup Weather] [!UpdateMeasureGroup Weather] [!UpdateMeter *] [!UpdateMeter *] [!Redraw] [!Log "Unable to connect to Weather.com." Error]
OnRegExpErrorAction=[!EnableMeasureGroup Weather] [!UpdateMeasureGroup Weather] [!UpdateMeter *] [!UpdateMeter *] [!Redraw] [!Log "Something went wrong." Error]

DynamicVariables=1
UpdateDivider=-1
Disabled=1

; ================================================

[mWeatherCurrentTemperature]
Group=Weather
Measure=WebParser
URL=[mWeatherParent]
StringIndex=1
RegExp=(?siU)"temperature":#WeatherRegExpNumber#[,}\]]
StringIndex2=1
RegExpSubstitute=1
Substitute="#WeatherSubstitute#", "^$":"--"
Last edited by sl23 on May 17th, 2024, 9:38 am, edited 1 time in total.
- MuLab -
User avatar
jsmorley
Developer
Posts: 22649
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Weather skin RegEx error.

Post by jsmorley »

Change the variable WeatherAPIKey=21d8a80b3d6b444998a80b3d6b1449d3 to WeatherAPIKey=71f92ea9dd2f4790b92ea9dd2f779061 in WeatherParser.ini, then save and refresh the skin.
User avatar
sl23
Posts: 1451
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Weather skin RegEx error.

Post by sl23 »

oh excellent! Thank you :thumbup:
Out of curiosity, why does this change every now an then?
How do I find this info to update it in future?
- MuLab -
User avatar
SilverAzide
Rainmeter Sage
Posts: 2692
Joined: March 23rd, 2015, 5:26 pm

Re: Weather skin RegEx error.

Post by SilverAzide »

sl23 wrote: May 17th, 2024, 8:21 am Out of curiosity, why does this change every now an then?
How do I find this info to update it in future?
You'd have to ask the folks at weather.com why, as they are the ones changing the key. My guess is they do it intentionally to disrupt anyone who is using their key for free instead of paying for it. Their business model is to drive people to their website so they can shove ads in people's faces, and not to support people bypassing ads and grabbing their data without paying for it. Cross your fingers that they don't start changing the key EVERY DAY.

The easiest way to find the key is to let folks in the community find it and post it here.
Gadgets Wiki GitHub More Gadgets...
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5452
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Weather skin RegEx error.

Post by eclectic-tech »

sl23 wrote: May 17th, 2024, 8:21 am oh excellent! Thank you :thumbup:
Out of curiosity, why does this change every now an then?
How do I find this info to update it in future?
(Code removed) There are ways, but it is better just to update the variable
apikey.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 7785
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Weather skin RegEx error.

Post by Yincognito »

SilverAzide wrote: May 17th, 2024, 11:50 am Cross your fingers that they don't start changing the key EVERY DAY.
Currently, they seem to change it gradually by region, since, if you look in the forum, the present key was actually posted earlier than these last few days (if I'm not mistaken, eclectic-tech did it in Jan this year). This is somewhat similar to how they migrated from V2 to V3 back when we were struggling with both versions. Me, I'm more interested that they keep the JSON embedded in the page itself, so standard parsing of it can be used as a fallback without needing a key at all. A bit more work with the backslash escaping, but worth it as a plan B.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1451
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Weather skin RegEx error.

Post by sl23 »

I didn't know it was a paid for service! I thought it was free. Makes sense now why it keeps changing.
- MuLab -
User avatar
SilverAzide
Rainmeter Sage
Posts: 2692
Joined: March 23rd, 2015, 5:26 pm

Re: Weather skin RegEx error.

Post by SilverAzide »

eclectic-tech wrote: May 17th, 2024, 12:04 pm You can try this code to display the current APIKey used by TWC (until they make another change :twisted: )
This would be a nice snippet to incorporate into a skin to allow it to "self-heal" in the event of a key change. :thumbup:
Gadgets Wiki GitHub More Gadgets...
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5452
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Weather skin RegEx error.

Post by eclectic-tech »

SilverAzide wrote: May 17th, 2024, 8:23 pm This would be a nice snippet to incorporate into a skin to allow it to "self-heal" in the event of a key change. :thumbup:
Yes! I have added this (not "self-healing") but easy to use methods in a few of my skins.

The Access suite can update the APIKey by clicking a label in the settings skin.
The Weatherview skin includes a GetAPIKey.ini skin that will update the APIKey value when you load it.

Feel free to look at the code for either method of adding this feature to your weather skin.
User avatar
Yincognito
Rainmeter Sage
Posts: 7785
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Weather skin RegEx error.

Post by Yincognito »

SilverAzide wrote: May 17th, 2024, 8:23 pm This would be a nice snippet to incorporate into a skin to allow it to "self-heal" in the event of a key change. :thumbup:
eclectic-tech wrote: May 17th, 2024, 8:38 pmYes! I have added this (not "self-healing") but easy to use methods in a few of my skins.
I personally would advise against publishing all the details about that on a large scale, because of this, but as you wish. I mean, it's nice and everything, but it reveals our how-to (and not just our what-with) in a way that makes it trivial to stop it. An InputBox where you can enter the key should be more than enough for most users...
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth