Weather: add option --weather-location

This commit is contained in:
李通洲
2023-07-19 10:55:13 +08:00
parent 3c5c2d2ca8
commit e25eed5896
5 changed files with 28 additions and 1 deletions
+1
View File
@@ -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)
+4
View File
@@ -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",
+5
View File
@@ -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
+1
View File
@@ -9,6 +9,7 @@ typedef struct FFWeatherOptions
const char* moduleName;
FFModuleArgs moduleArgs;
FFstrbuf location;
FFstrbuf outputFormat;
uint32_t timeout;
} FFWeatherOptions;
+17 -1
View File
@@ -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));