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

[weather-api-widget] local lang de: coordinates with comma instead of point, result in wrong coordinates for the api call #461

Open
forTT78 opened this issue Jan 7, 2025 · 3 comments

Comments

@forTT78
Copy link

forTT78 commented Jan 7, 2025

Hello,
I would like to use the weather-api-widget. I noticed strange temperatures.

awesome v4.3-1681-g0f950cbb-dirty (Too long)
 • Compiled against Lua 5.3.6 (running with Lua 5.3)
 • API level: 4
 • D-Bus support: yes
 • xcb-errors support: no
 • execinfo support: yes
 • xcb-randr version: 1.6
 • LGI version: 0.9.2
 • Transparency enabled: yes
 • Custom search paths: no

Widget configuration in rc.lua:

┊   ┊   ┊   weather_widget({                                                           
┊   ┊   ┊   ┊   api_key='API_key',                             
┊   ┊   ┊   ┊   coordinates = {52.36, 10.76},                                 
┊   ┊   ┊   ┊   time_format_12h = false,                                               
┊   ┊   ┊   ┊   units = 'metric',                                                      
┊   ┊   ┊   ┊   both_units_widget = false,                                             
┊   ┊   ┊   ┊   font_name = 'Carter One',                                              
┊   ┊   ┊   ┊   icons = 'VitalyGorbachev',                                             
┊   ┊   ┊   ┊   icons_extension = '.svg',                                              
┊   ┊   ┊   ┊   --                  icons = 'weather-underground-icons',               
┊   ┊   ┊   ┊   --                  icons_extension = '.png',                          
┊   ┊   ┊   ┊   show_hourly_forecast = true,                                           
┊   ┊   ┊   ┊   show_daily_forecast = true,                                            
┊   ┊   ┊   ┊   timeout = 180,                                                         
┊   ┊   ┊   }),                

generates:

DEBUG: coordinates: table: 0x5e9abaffea70
DEBUG: args.coordinates 1: 52,36
DEBUG: args.coordinates 2: 10,76
DEBUG: coordinates 1: 52,36
DEBUG: coordinates 2: 10,76
DEBUG: weather_api call: https://api.weatherapi.com/v1/forecast.json?q=52,36,10,76&key=API_key&units=metric&lang=de&days=3
---> Mexico

In the API call the coordinates should be with point instead of comma.

https://api.weatherapi.com/v1/forecast.json?q=52.36,10.76&key=API_key&units=metric&lang=de&days=3
--> Germany

Any hint how I can set the coordinates right in the configuration?

@Ryuno-Ki
Copy link
Contributor

Ryuno-Ki commented Jan 8, 2025

Hey there 👋

I wrote the plugin.

According to https://www.weatherapi.com/docs/#intro-request-param the Longitude and Latitude are denoted with a dot and separated by comma.

The code merely stitches together the URL:

'?q=' .. coordinates[1] .. ',' .. coordinates[2] .. '&key=' .. api_key ..

I double checked and I have the coordinates with the right format (decimal separated using dots in the config).

If you want to use commas, coordinates = {'52,36', '10,76'} should work.

@forTT78
Copy link
Author

forTT78 commented Jan 8, 2025

Hi, thank you for your feedback.

According to https://www.weatherapi.com/docs/#intro-request-param the Longitude and Latitude are denoted with a dot and separated by comma.

Yes, I understand. It works only with coordinates with a dot.

If you want to use commas, coordinates = {'52,36', '10,76'} should work.

Why? No that is not my question.

If I try with coordinates = {'52,36', '10,76'}
it generates:
weather_api call: https://api.weatherapi.com/v1/forecast.json?q=52,36,10,76&key=API_key&units=metric&lang=de&days=3

But with this format of coordinates = {'52.36', '10.76'} it works for me.

It generates:
weather_api call: https://api.weatherapi.com/v1/forecast.json?q=52.36,10.76&key=API_key&units=metric&lang=de&days=3

I think the issue is together with the locales.
In the widget configuration I entered:
coordinates = {52.36, 10.76}

But for any reason the coordinates were interpreted as numbers with a comma as separation mark.
Out of curiosity, I would like to understand why this is the case.

But for the moment, the solution is to set the values
like here coordinates = {'52.36', '10.76'} .

Maybe you could make a hint on the documentation?

best regards

@Ryuno-Ki
Copy link
Contributor

Ryuno-Ki commented Jan 8, 2025

Glad you found a solution!

According to Lua's spec numbers are using a dot as a separation mark. Really weird that you have an interpolation as a comma.

Find the PR in #462

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

No branches or pull requests

2 participants