Jax-Core / ModularClocks

Gallery of animated & modern clock widgets
MIT License
47 stars 7 forks source link

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

Open slaugaus opened 1 year ago

slaugaus commented 1 year ago

https://github.com/Jax-Core/ModularClocks/blob/f61896dc1da6a3f0e47a1ba3d480a6fdd889b4d5/%40Resources/Includes/GlobalWeather.inc#L22

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]}}]}```
JotaRata commented 1 year ago

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

mastra90 commented 1 year ago

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\\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\\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

Onaterdem commented 1 year ago

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).
scottmeup commented 9 months ago

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])
Onaterdem commented 6 months ago

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