zanyrain

zanyrain

github
twitter_id

Add custom location weather support to Gnome Weather (Community Edition)

Gnome Weather is a built-in weather forecast app in Gnome, which relies on the libgweather library. It provides multiple data sources, but it seems that not all of these sources are enabled by default in the distribution. Our great international Rock Home Town cannot be found. Super knows it and must be unhappy.

There are two main ways to add location support to it:

  • Official recommendation: Submit the location information of the city for location.xml

    It is useless to directly modify it here. This xml file is converted to a bin file during compilation for the program to read.

    To be honest, I don't quite understand its logic. It is obviously implemented on several server sides. Why do we have to configure such a file, and the content of the file is somewhat related to airports (physical airports).

  • Modify the code

    You can implement custom data sources for it, such as adding an implementation of weather.cma.cn.

Is there a way suitable for us ordinary people? The answer is yes.

gsettings get org.gnome.shell.weather locations

Here I will return a string, which may be the cached data I checked before.

[<(uint32 2, <('Beijing', 'ZBAA', false, [(0.69696814214530467, 2.0295270260429752)], @a(dd) [])>)>, <(uint32 2, <('Beijing', 'ZBAA', true, [(0.69696814214530467, 2.0295270260429752)], [(0.69689057971334611, 2.0313596217575696)])>)>, <(uint32 2, <('Shanghai', 'ZSSS', true, [(0.54396095602266359, 2.1194114825206833)], [(0.54493057368860898, 2.1198429802716539)])>)>, <(uint32 2, <('Ashiya Air Base', 'RJFA', false, [(0.59137572239964786, 2.2802726677305918)], @a(dd) [])>)>]

First of all, it is definitely an array outside. By flipping the code, we can easily find it.

https://gitlab.gnome.org/GNOME/libgweather/-/blob/main/libgweather/gweather-location.c?ref_type=heads#L1423

If the string is beautified, it will look like this:

<(
    uint32 2, 
    <(
        'Beijing', 
        'ZBAA', 
        false, 
        [
            (0.69696814214530467, 2.0295270260429752)
        ], 
        @a(dd) []
    )>
)>

Compared with the above code

uint32 2 represents the version, which is 2

Beijing city name

ZBAA airport or terminal code

false whether this data is for a city (true) or an airport (false)

The array below represents latitude, longitude, in radians, using the formula angle * (pi / 180)

The second array is optional, representing the parent location (possibly an alternative). If there is none, pass @a(dd) []

For example, the latitude and longitude of Shijiazhuang City, Qiaoxi District are 38.04139, 114.47861

Then you can get

<(uint32 2, <('Shijiazhuang', '', true, [(0.663947508, 1.998028668)], @a(dd) [])>)>

Set them respectively

gsettings set org.gnome.shell.weather locations "[concatenated content]"
gsettings set org.gnome.Weather locations "[concatenated content]"

This way, it will work in the Gnome Weather App, but the display in the Shell notification bar is still problematic.

The weather service integrated in Shell seems to have some logical problems. It will match the nearest place in location.xml. Here I was located in Taiyuan, but after turning off the location service in Settings-> Privacy, it shows Shijiazhuang.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.