diff --git a/CHANGELOG.md b/CHANGELOG.md index 756fcf836..3e7648dc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Features: * Add option `--processing-timeout` to the timeout when waiting for child processes. * Public IP module prints the IP location if `--publicip-url` is not set (PublicIP) * Add option `--localip-default-route-only` (LocalIP) +* Add option `--weather-location` (Weather) Bugfixes: * Fix possible hanging (TerminalFont, #493) diff --git a/doc/json_schema.json b/doc/json_schema.json index 9e4238b81..46a8cac71 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1006,6 +1006,10 @@ "type": { "const": "weather" }, + "location": { + "title": "The location to display", + "type": "string" + }, "timeout": { "title": "Time in milliseconds to wait for the weather server to respond", "type": "integer", diff --git a/src/data/config_user.txt b/src/data/config_user.txt index d5eccdc8e..3b62ac180 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -206,6 +206,11 @@ # Default is 0 (disabled). #--publicip-timeout 0 +# Weather location option: +# Sets location to be used. It must be URI encoded. +# Default is empty (guessing by public IP) +#--weather-location "Location" + # Weather output format option: # Sets the weather format to be used. It must be URI encoded. # See: https://github.com/chubin/wttr.in#one-line-output diff --git a/src/modules/weather/option.h b/src/modules/weather/option.h index d481fb6b7..6f82f5388 100644 --- a/src/modules/weather/option.h +++ b/src/modules/weather/option.h @@ -9,6 +9,7 @@ typedef struct FFWeatherOptions const char* moduleName; FFModuleArgs moduleArgs; + FFstrbuf location; FFstrbuf outputFormat; uint32_t timeout; } FFWeatherOptions; diff --git a/src/modules/weather/weather.c b/src/modules/weather/weather.c index 84f34ee82..cbf5cb524 100644 --- a/src/modules/weather/weather.c +++ b/src/modules/weather/weather.c @@ -11,7 +11,10 @@ static int status = -1; void ffPrepareWeather(FFWeatherOptions* options) { - FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/?format="); + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/"); + if (options->location.length) + ffStrbufAppend(&path, &options->location); + ffStrbufAppendS(&path, "?format="); ffStrbufAppend(&path, &options->outputFormat); status = ffNetworkingSendHttpRequest(&state, "wttr.in", path.chars, "User-Agent: curl/0.0.0\r\n"); } @@ -55,6 +58,7 @@ void ffInitWeatherOptions(FFWeatherOptions* options) options->moduleName = FF_WEATHER_MODULE_NAME; ffOptionInitModuleArg(&options->moduleArgs); + ffStrbufInit(&options->location); ffStrbufInitS(&options->outputFormat, "%t+-+%C+(%l)"); options->timeout = 0; } @@ -66,6 +70,12 @@ bool ffParseWeatherCommandOptions(FFWeatherOptions* options, const char* key, co if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; + if (ffStrEqualsIgnCase(subKey, "location")) + { + ffOptionParseString(key, value, &options->location); + return true; + } + if (ffStrEqualsIgnCase(subKey, "output-format")) { ffOptionParseString(key, value, &options->outputFormat); @@ -106,6 +116,12 @@ void ffParseWeatherJsonObject(yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) continue; + if (ffStrEqualsIgnCase(key, "location")) + { + ffStrbufSetS(&options.location, yyjson_get_str(val)); + continue; + } + if (ffStrEqualsIgnCase(key, "outputFormat")) { ffStrbufSetS(&options.outputFormat, yyjson_get_str(val));