Added location from master to current branch.

This commit is contained in:
Jas Singh
2024-07-26 23:17:36 -07:00
parent 9e94bcd57d
commit cd0a14c146

View File

@@ -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,15 +17,20 @@ 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) => {
if (typeof res === "string") { try {
theWeather.value = JSON.parse(res); if (typeof res === "string") {
theWeather.value = JSON.parse(res);
}
} catch (error) {
console.error(`Failed to parse weather data: ${error}`);
} }
}) })
.catch((err) => { .catch((err) => {