Update pika-hyprland-settings/etc/skel/.config/ags/widgets/weather.js
This commit is contained in:
parent
34ecee9a2b
commit
afda55fa52
@ -1,7 +1,7 @@
|
||||
const { Widget } = ags;
|
||||
const { execAsync } = ags.Utils;
|
||||
import barConfig from '../barConfig.js';
|
||||
import { getWeatherSymbol, getTemp } from '../lib.js';
|
||||
import { getWeatherSymbol, getTemp, getWeatherDesc } from '../lib.js';
|
||||
|
||||
export const Weather = () => Widget.Box({
|
||||
halign: 'end',
|
||||
@ -23,15 +23,27 @@ export const Weather = () => Widget.Box({
|
||||
}),
|
||||
],
|
||||
connections: [[barConfig?.weatherUpdateInterval * 1000, async box => {
|
||||
setTimeout(() => {
|
||||
execAsync(`curl https://wttr.in/${barConfig?.city}?format=j1`)
|
||||
.then(output => {
|
||||
const weather = JSON.parse(output);
|
||||
const weatherCode = weather.current_condition[0].weatherCode;
|
||||
box.tooltipText = weather.current_condition[0].weatherDesc[0].value;
|
||||
box.children[0].label = getWeatherSymbol(weatherCode);
|
||||
box.children[1].label = getTemp(weather.current_condition[0].temp_C);
|
||||
}).catch(console.error)
|
||||
}, 5000);
|
||||
getWeather(box);
|
||||
setTimeout(() => { getWeather(box) }, 10000);
|
||||
}]],
|
||||
});
|
||||
|
||||
function getWeather(box) {
|
||||
let latLng = [0, 0];
|
||||
execAsync(`curl https://geocoding-api.open-meteo.com/v1/search?name=${barConfig?.city}&count=1&language=en&format=json`)
|
||||
.then(output => {
|
||||
const geocoding = JSON.parse(output);
|
||||
if (geocoding.results.length === 0) {
|
||||
return;
|
||||
}
|
||||
latLng = [geocoding.results[0].latitude, geocoding.results[0].longitude];
|
||||
execAsync(`curl https://api.open-meteo.com/v1/forecast?latitude=${latLng[0]}&longitude=${latLng[1]}¤t=temperature_2m,is_day,weather_code`)
|
||||
.then(output => {
|
||||
const weather = JSON.parse(output);
|
||||
const weatherCode = weather.current.weather_code;
|
||||
box.tooltipText = getWeatherDesc(weatherCode);
|
||||
box.children[0].label = getWeatherSymbol(weatherCode);
|
||||
box.children[1].label = getTemp(Math.round(weather.current.temperature_2m) + "");
|
||||
}).catch(console.error)
|
||||
}).catch(console.error)
|
||||
}
|
Loading…
Reference in New Issue
Block a user