#!/bin/bash

source $(dirname $0)/00-config
mkdir -p $WORKDATADIR/04

for qfile in $WORKDATADIR/03/*; do
  outfile="$WORKDATADIR/04/$(basename $qfile).json"
  if [ ! -s "$outfile" ]; then # replace with proper check if the file is formatted well
    echo "------ querying $(basename $qfile) ------"
    wget -O "$outfile" --post-file="$qfile" "https://maps.mail.ru/osm/tools/overpass/api/interpreter"
    if [ "$?" != 0 ]; then
      echo "an error occured"
      rm "$outfile"
      exit 1
    fi
  fi
done
