Jax-Core / ModularClocks

Gallery of animated & modern clock widgets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regex for Nominatim API call doesn't account for spaces, causing incorrect weather data

slaugaus opened this issue · comments

RegExp=(?siU)"features":\[{"type":"Feature","properties":{"geocoding":{.*,"label":"(.*)",.*,"admin":{.*?"level\d+":"(.*)"}}},"geometry":{"type":"Point","coordinates":\[(.*),(.*)\]}}\]

The offending spaces are in the value of geometry, as seen near the end of this response for Hell, Michigan. Removing them makes the regex work as intended.

{"type":"FeatureCollection","geocoding":{"version":"0.1.0","attribution":"Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright","licence":"ODbL","query":"Hell, MI"},"features":[{"type":"Feature","properties":{"geocoding":{"place_id":415106,"osm_type":"node","osm_id":154309316,"osm_key":"place","osm_value":"hamlet","type":"district","label":"Hell, Putnam Township, Livingston County, Michigan, United States","name":"Hell","city":"Putnam Township","county":"Livingston County","state":"Michigan","country":"United States","country_code":"us","admin":{"level7":"Putnam Township","level7":"Putnam Township","level6":"Livingston County","level6":"Livingston County","level4":"Michigan","level4":"Michigan"}}},"geometry":{"type": "Point","coordinates": [-83.9849477, 42.4347571]}}]}```

I tested it with regex101.com and came up with this

(?siU)"features":\[{"type":"Feature","properties":{"geocoding":{.*,"label":"(.*)",.*,"admin":{.*?"level\d+":"(.*)"}}},"geometry":{"type": "Point","coordinates": \[(.*),(.*)\]}}\]

Now I'm facing a problem with [mCurrentParent] which also reports a Regex error but I cannot replicate on the website

Can confirm slaugaus' fix works, great work.
But the above link is to the pull request, not the repo and overall the install instructions could be better.

To implement the fix:

  1. Close Rainmeter

  2. Go here: https://github.com/slaugaus/ModularClocks/tree/main

  3. Click the green Code button > Download ZIP

  4. Extract ZIP and copy all contents, then paste it in the below file path to replace all files.
    C:\Users<USERNAME>\AppData\Roaming\JaxCore\InstalledComponents\ModularClocks

  5. Download this: https://github.com/e2e8/rainmeter-jsonparser/releases/download/1.0/JsonParser1.0x64.zip

  6. Extract the JsonParser.dll file to either one of these locations. Either location works for me:
    Location 1: C:\Program Files\Rainmeter\Plugins
    Location 2: C:\Users<USERNAME>\AppData\Roaming\Rainmeter\Plugins

  7. Open Rainmeter and see that the weather data is now correct, assuming you've set the location correctly in the JaxCore settings

Hello, I've also come across this issue yesterday and was trying for a fix, to no avail.

I'm now trying the above fix by @slaugaus but am getting constant errors which read Error reading JToken from JsonReader. Path '', line 0, position 0. (ModularClocks\Main\Main.ini - [VARIABLENAME]).

I'm not well-versed in Regex, or Json parsing, so I'm not sure if I can come up with a solution myself. Can anybody be of any help?

Edit:

Some things I've realized:

  1. When trying to [!Log [mLocationParent]], only 512 letters appear in the log - I am not sure if this is a limitation of the RegExp which is trying to capture everything in one variable, or a limitation of logging. Reason 1 would explain the aforementioned JsonReader error since the json begins with { and ends abruptly.
  2. I've tried to edit the RegExp without changing the file to use the new JsonParser method. Adding a whitespace or a * after "type": and "coordinates": gives a RegExp matching error (-1).

It looks like it broke again.

Constantly spitting out these errors:

Unexpected character encountered while parsing value: <. Path '', line 0, position 0. (ModularClocks\Main\Main.ini - [mLocationCity])
Unexpected character encountered while parsing value: <. Path '', line 0, position 0. (ModularClocks\Main\Main.ini - [mLocationLon])
Unexpected character encountered while parsing value: <. Path '', line 0, position 0. (ModularClocks\Main\Main.ini - [mLocationLat])

It broke again, but it seems like an API key change this time around. I don't want to directly share it for any possible legal troubles, but you can find the new key on the Rainmeter forums. Just search for weather.com.

Edit: Oh, also, regarding my above issue, I simply fixed it by hardcoding the mLocationLon and mLocationLat values as strings. Simply do this:

[mLocationLat]
Measure=String
String="YOUR_LATITUDE_HERE"
; previous mLocationLat code