weather-tool: Handle bad location-data by trying to get it again

This commit is contained in:
K. Lange 2021-07-26 14:29:15 +09:00
parent 65529edfb4
commit 817b92837a

View File

@ -31,11 +31,13 @@ int main(int argc, char * argv[]) {
* get a location from the user's external IP... */
if (!strcmp(city, "guess")) {
/* See if the location data already exists... */
if (access(LOCATION_DATA_PATH, R_OK)) {
Value * locationData = json_parse_file(LOCATION_DATA_PATH);
if (!locationData) {
sprintf(cmdline, "fetch -o \"" LOCATION_DATA_PATH "\" \"http://ip-api.com/json/?fields=lat,lon,city\"");
system(cmdline);
locationData = json_parse_file(LOCATION_DATA_PATH);
}
Value * locationData = json_parse_file(LOCATION_DATA_PATH);
/* If we still failed to load it, then bail. */
if (!locationData) {
fprintf(stderr, "%s: city field was set to 'guess' but failed to acquire data from IP geolocation service\n", argv[0]);
return 1;