#!/usr/bin/python

############################################################################
# This is getmap.py version 0.1alpha, a virgilio.it's maps download software
#   Copyright (C) 2004 Enrico Cherubini
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author: Enrico Cherubini
# Email: kevin@bestkevin.com
############################################################################


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

