#!/bin/bash

source "$(dirname $0)/00-config"
mkdir -p $WORKDATADIR/02
rm $WORKDATADIR/02/*

IFS=","

for district in $WORKDATADIR/01/*; do
  qcounter=0
  for street in $(cat $district); do
    outfile="$WORKDATADIR/02/$(basename $district)-$(( $qcounter / 5 ))" # limit to 5 queries per file
    qcounter="$(( $qcounter + 1 ))"
    str=$(echo "$street" | sed -e 's/^[[:space:]]*//')
    printf "way(area.searchArea)[\"name\"=\"%s\"][\"highway\"~\"residential|motorway|unclassified|trunk|primary|secondary|tertiary|living_street|service|footway|pedestrian\"];\n" "$str" >> $outfile
  done
done
