this post was submitted on 29 Nov 2023
10 points (100.0% liked)

Linux Brasil

565 readers
21 users here now

Comunidade Lusófona de entusiastas Linux.

Bem vindo ao nosso agregado de links sobre Linux.


Geral

Wiki do c/Linux

Megathread do c/Linux

Chat

founded 1 year ago
MODERATORS
 

Faz uns 10 meses já que uso o Gnome e sempre me incomodou que minha cidade (com mais de um milhão de hab.) não era encotrada no programa Weather.

Varias vezes procurei soluções e nunca achei, até que encontrei essa thread ontem. Que o user Julian fez um script que resolve esse problema. você só tem que executar e inserir o nome da sua cidade e depois confirmar.

script

#!/bin/bash

if [[ ! -z "$(which gnome-weather)" ]]; then
	system=1
fi

if [[ ! -z "$(flatpak list | grep org.gnome.Weather)" ]]; then
	flatpak=1
fi

if [[ ! $system == 1 && ! $flatpak == 1 ]]; then
	echo "GNOME Weather isn't installed"
	exit
fi

if [[ ! -z "$*" ]]; then
	query="$*"
else
	read -p "Type the name of the location you want to add to GNOME Weather: " query
fi

query="$(echo $query | sed 's/ /+/g')"

request=$(curl "https://nominatim.openstreetmap.org/search?q=$query&format=json&limit=1" -s)

if [[ $request == "[]" ]]; then
	echo "No locations found, consider removing some search terms"
	exit
fi

read -p "If this is not the location you wanted, consider adding search terms
Are you sure you want to add $(echo $request | sed 's/.*"display_name":"//' | sed 's/".*//')? [y/n] : " answer

if [[ ! $answer == "y" ]]; then
	echo "Not adding location"
	exit
else
	echo "Adding location"
fi

id=$(echo $request | sed 's/.*"place_id"://' | sed 's/,.*//')

name=$(curl "https://nominatim.openstreetmap.org/details.php?place_id=$id&format=json" -s | sed 's/.*"name": "//' | sed 's/".*//')

lat=$(echo $request | sed 's/.*"lat":"//' | sed 's/".*//')
lat=$(echo "$lat / (180 / 3.141592654)" | bc -l)

lon=$(echo $request | sed 's/.*"lon":"//' | sed 's/".*//')
lon=$(echo "$lon / (180 / 3.141592654)" | bc -l)

if [[ $system == 1 ]]; then
	locations=$(gsettings get org.gnome.Weather locations)
fi

if [[ $flatpak == 1 ]]; then
	locations=$(flatpak run --command=gsettings org.gnome.Weather get org.gnome.Weather locations)
fi

location="<(uint32 2, <('$name', '', false, [($lat, $lon)], @a(dd) [])>)>"

if [[ $system == 1 ]]; then
	if [[ ! $(gsettings get org.gnome.Weather locations) == "@av []" ]]; then
		gsettings set org.gnome.Weather locations "$(echo $locations | sed "s|>]|>, $location]|")"
	else
		gsettings set org.gnome.Weather locations "[$location]"
	fi
fi

if [[ $flatpak == 1 ]]; then
	if [[ ! $(flatpak run --command=gsettings org.gnome.Weather get org.gnome.Weather locations) == "@av []" ]]; then
		flatpak run --command=gsettings org.gnome.Weather set org.gnome.Weather locations "$(echo $locations | sed "s|>]|>, $location]|")"
	else
		flatpak run --command=gsettings org.gnome.Weather set org.gnome.Weather locations "[$location]"
	fi
fi


Me ocorreu que algumas pessoas talvez não saibam executar scripts, então aqui um breve tutorial:

Como executar scripts no linux

  1. Salve o script em um arquivo de texto e salve com a extensão .sh
  2. Forneça permissão de execução: chmod u+x script.sh
  3. execute o script com duplo click ou ./script.sh
all 1 comments
sorted by: hot top controversial new old