#!/usr/bin/python

import urllib, os

LASTART=47.6 # Aumentando ci si sposta a Sud
LOSTART=6.30 # Aumentando ci si sposta a Est

LAEND=35.3
LOEND=18.32

DELTAX=0.025
DELTAY=0.01  # Devono diminuire !!! 0 e' equatore

XSIZE=640
YSIZE=512

ximages=((LOEND-LOSTART)/DELTAX)+1
yimages=((LASTART-LAEND)/DELTAY)+1
totimages=ximages*yimages

print "Images to get: "+str(totimages)

LANOW=LASTART
LONOW=LOSTART

while LANOW <= LAEND:
	while LONOW <= LOEND:
		print LANOW,LONOW
		try:
			about = os.stat(str(LANOW)+"-"+str(LONOW)+".gif")
			print "File "+str(LANOW)+"-"+str(LONOW)+".gif exists"
		except OSError:
			url = "http://mapserver.tuttocitta.it/ReadDll/MapRender.aspx?x="+str(LONOW)+"&y="+str(LANOW)+"&z=1&lx="+str(LONOW)+"&ly="+str(LANOW)+"&xpix="+str(XSIZE)+"&ypix="+str(YSIZE)+"&dz=1.7&cs="
			urllib.urlretrieve(url,str(LANOW)+"-"+str(LONOW)+".gif")

		LONOW=LONOW+DELTAX
	LONOW=LOSTART
	LANOW=LANOW-DELTAY

