Added location from master to current branch.
This commit is contained in:
@@ -6,7 +6,7 @@ import { Hourly } from "./hourly/index.js";
|
|||||||
import { Weather } from "lib/types/weather.js";
|
import { Weather } from "lib/types/weather.js";
|
||||||
import { DEFAULT_WEATHER } from "lib/types/defaults/weather.js";
|
import { DEFAULT_WEATHER } from "lib/types/defaults/weather.js";
|
||||||
|
|
||||||
const { key, interval } = options.menus.clock.weather;
|
const { key, interval, location } = options.menus.clock.weather;
|
||||||
|
|
||||||
const theWeather = Variable<Weather>(DEFAULT_WEATHER);
|
const theWeather = Variable<Weather>(DEFAULT_WEATHER);
|
||||||
|
|
||||||
@@ -17,16 +17,21 @@ const WeatherWidget = () => {
|
|||||||
class_name: "weather-container-box",
|
class_name: "weather-container-box",
|
||||||
setup: (self) => {
|
setup: (self) => {
|
||||||
Utils.merge(
|
Utils.merge(
|
||||||
[key.bind("value"), interval.bind("value")],
|
[key.bind("value"), interval.bind("value"), location.bind("value")],
|
||||||
(weatherKey, weatherInterval) => {
|
(weatherKey, weatherInterval, loc) => {
|
||||||
Utils.interval(weatherInterval, () => {
|
Utils.interval(weatherInterval, () => {
|
||||||
|
const formattedLocation = loc.replace(" ", "%20");
|
||||||
Utils.execAsync(
|
Utils.execAsync(
|
||||||
`curl "https://api.weatherapi.com/v1/forecast.json?key=${weatherKey}&q=93722&days=1&aqi=no&alerts=no"`,
|
`curl "https://api.weatherapi.com/v1/forecast.json?key=${weatherKey}&q=${formattedLocation}&days=1&aqi=no&alerts=no"`,
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
try {
|
||||||
if (typeof res === "string") {
|
if (typeof res === "string") {
|
||||||
theWeather.value = JSON.parse(res);
|
theWeather.value = JSON.parse(res);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to parse weather data: ${error}`);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(`Failed to fetch weather: ${err}`);
|
console.error(`Failed to fetch weather: ${err}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user