#!/bin/bash
mkdir -p NOK/
echo num,date,adresse,code_postal,ville,mV/m,distance,latitude,longitude > anfr.csv
for mesure in `seq 1 16350`; do
	echo doing $mesure
	#16350 is found by dichotomy on cartoradio.fr

	if [ -f $mesure.htm ]; then 
		max=`grep -A1 GSM.[0-9] $mesure.htm|grep -v GSM|grep -v '^--$'|sed "s/<TD ALIGN=CENTER><p><b> *\(.*\),\(.\).*$/\1\200/"|sort -n|tail -1`
		if [ "$max" != "" ]; then
			date=`grep -A1 "Date de la mesure" $mesure.htm |tail -1|sed "s/^.*<p>\(.*\)<.p>.*$/\1/"`
			rue=`grep "Rue :" $mesure.htm | sed "s/\(.*\)<\/p.*> \(.*\) :<\/TD.*<p>\(.*\)<\/p.*$/\1 \2 \3/"|sed "s/,/-/g"`
			cp=`grep "Code postal :" $mesure.htm|sed "s/^.*<p>\([0-9]*\)<.p>.*$/\1/"`
			ville=`grep "Ville :" $mesure.htm |sed "s/^.*<p>\(.*\)<.p>.*$/\1/"`
			lat=`grep "Latitude :" $mesure.htm |sed "s/^.*<p>\(.*\)<.p>.*$/\1/"`
			long=`grep "Longitude :" $mesure.htm |sed "s/^.*<p>\(.*\)<.p>.*$/\1/"`
			distance=`grep -A3 font.color=black.GSM $mesure.htm |grep 662a85|sed "s/.*662a85>\(.*\)<\/font.*$/\1/"|sort -n|head -1` 
			echo "$mesure,$date,$rue,$cp,$ville,$max,$distance,$lat,$long" >> anfr.csv
		fi
	fi
done
