Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
slaugaus opened this issue Aug 22, 2023 · 5 comments · May be fixed by #16
Open

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

slaugaus opened this issue Aug 22, 2023 · 5 comments · May be fixed by #16

Comments

@slaugaus
Copy link

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]}}]}```
@JotaRata
Copy link

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
Copy link

mastra90 commented Oct 1, 2023

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

@Onaterdem
Copy link

Onaterdem commented Nov 13, 2023

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
Copy link

scottmeup commented Mar 4, 2024

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
Copy link

Onaterdem commented May 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants