import sys
import urllib
import urllib2

def download(output_file, extent):
    url = 'http://api.openstreetmap.org/api/0.6/map'

    encoded_url = '{0}?bbox={1}'.format(url, extent)
    print encoded_url
    response = urllib2.urlopen(encoded_url)
    

    with open(output_file, 'w') as writeable:
        writeable.write(response.read())
  
if __name__ == '__main__':
    output_file = sys.argv[1]
    extent = sys.argv[2]

    if not output_file:
        raise InputError('Output file required')
    if not (extent or len(extent.split(',')) == 4):
        raise InputError('Extent is required in format XMIN,YMIN,XMAX,YMAX')

    download(output_file, extent)

@@ -39,38 +39,35 @@
 2%0A%0Adef download(
-output
+map
 _file, extent):%0A
@@ -332,16 +332,857 @@
 read())%0A
+        %0Adef osm2pgrouting(map_file, config_file, database, username, password):%0A    osm2pgrouting = 'osm2pgrouting'%0A    %0A    upload_command = '%7B0%7D -file %7B1%7D -conf %7B2%7D -dbname %7B3%7D -user %7B4%7D -passwd %7B5%7D'.format(osm2pgrouting, %0A                                                                                        map_file,  %0A                                                                                        config_file,  %0A                                                                                        database,  %0A                                                                                        username, %0A                                                                                        password)%0A%0A    upload_response = subprocess.Popen(upload_command, stdout=PIPE).stdout.read()%0A    %0A    print upload_response%0A%0A
   %0Aif __
@@ -1207,22 +1207,44 @@
 _':%0A    
-output
+extent = sys.argv%5B1%5D%0A    map
 _file = 
@@ -1256,35 +1256,126 @@
 rgv%5B
-1
+2
 %5D%0A    
-extent = sys.argv%5B2%5D
+config_file = sys.argv%5B3%5D%0A    database = sys.argv%5B4%5D%0A    username = sys.argv%5B5%5D%0A    password = sys.argv%5B6%5D%0A    
 %0A%0A  
@@ -1578,39 +1578,125 @@
 X')%0A
-%0A    download(output_file, extent
+        %0A        %0A%0A    download(extent, map_file)%0A    osm2pgrouting(map_file, config_file, database, username, password
 )%0A

add upload to postgresql database with osm2pgrout