Weather: support JSON format

This commit is contained in:
李通洲
2023-09-13 18:38:02 +08:00
parent 63c29b10fe
commit 013abe2b3e
2 changed files with 16 additions and 1 deletions
+15 -1
View File
@@ -33,7 +33,7 @@ void ffPrintWeather(FFWeatherOptions* options)
void ffInitWeatherOptions(FFWeatherOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WEATHER_MODULE_NAME, ffParseWeatherCommandOptions, ffParseWeatherJsonObject, ffPrintWeather, NULL);
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WEATHER_MODULE_NAME, ffParseWeatherCommandOptions, ffParseWeatherJsonObject, ffPrintWeather, ffGenerateWeatherJson);
ffOptionInitModuleArg(&options->moduleArgs);
ffStrbufInit(&options->location);
@@ -110,3 +110,17 @@ void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module)
ffPrintError(FF_WEATHER_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateWeatherJson(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate();
const char* error = ffDetectWeather(options, &result);
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
}
yyjson_mut_obj_add_strbuf(doc, module, "result", &result);
}
+1
View File
@@ -11,3 +11,4 @@ void ffInitWeatherOptions(FFWeatherOptions* options);
bool ffParseWeatherCommandOptions(FFWeatherOptions* options, const char* key, const char* value);
void ffDestroyWeatherOptions(FFWeatherOptions* options);
void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module);
void ffGenerateWeatherJson(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);