osm-restaurants: display fetching in stderr, do not fail on malformed opening hours

This commit is contained in:
2022-11-23 09:57:11 +01:00
parent e4c08f0d0b
commit 84ad803482

View File

@@ -80,9 +80,10 @@ const overpassQuery = `
out; out;
`; `;
const restaurantOpen = (restaurant: OsmNode) => function restaurantOpen(restaurant: OsmNode): boolean {
"opening_hours" in restaurant.tags if ("opening_hours" in restaurant.tags)
? new openingHours(restaurant.tags.opening_hours, { try {
return new openingHours(restaurant.tags.opening_hours, {
lat: restaurant.lat, lat: restaurant.lat,
lon: restaurant.lon, lon: restaurant.lon,
address: { address: {
@@ -91,8 +92,12 @@ const restaurantOpen = (restaurant: OsmNode) =>
? restaurant.tags["addr:country"].toLowerCase() ? restaurant.tags["addr:country"].toLowerCase()
: argv.country, : argv.country,
}, },
}).getState() }).getState();
: true; } catch {
return true;
}
else return true;
}
const withRestaurants = (callback: (restaurants: OsmNode[]) => any) => { const withRestaurants = (callback: (restaurants: OsmNode[]) => any) => {
const cachePath = getCachePath(overpassQuery); const cachePath = getCachePath(overpassQuery);
@@ -102,7 +107,7 @@ const withRestaurants = (callback: (restaurants: OsmNode[]) => any) => {
) )
callback(JSON.parse(readFileSync(cachePath))); callback(JSON.parse(readFileSync(cachePath)));
else { else {
console.log("fetching"); console.error("fetching", overpassQuery);
return fetch(argv.endpoint, { return fetch(argv.endpoint, {
method: "POST", method: "POST",
body: overpassQuery, body: overpassQuery,