kml_template = '''<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
 <Document>
   <Placemark>
     <name>Brown pushpin invasion</name>
     <description>Andes! Look out!</description>
     <Style>
       <IconStyle>
         <scale>8.1</scale>
         <Icon>
           <href>http://maps.google.com/mapfiles/kml/pushpin/wht-pushpin.png</href>
         </Icon>
         <color>ff71C197</color>
       </IconStyle>
     </Style>
     <Point>
       <coordinates>-71.39958246985421,-41.82698688556646,0</coordinates>
     </Point>
   </Placemark>
 </Document>
</kml>'''

test_coords = [['CIT', -71.39958246985421, 41.82698688556646], ['DC', -75, 39], ['Stonehenge', -0.3, 45]]

def makeKml(coords, filename):
    fid = open(filename, 'w')
    fid.write('''<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
 <Document>''')
    for coordinate in coords:
        fid.write(placemarkCode(coordinate))
    fid.write(''' </Document>
</kml>''')
    fid.close()

def placemarkCode(coord):
    code = '   <Placemark>\n'
    code = code + '     <name>' + coord[0] + '</name>\n'
    code = code + '''     <description></description>
     <Style>
       <IconStyle>
         <scale>1.1</scale>
         <Icon>
           <href>http://maps.google.com/mapfiles/kml/pushpin/wht-pushpin.png</href>
         </Icon>
         <color>ff71C197</color>
       </IconStyle>
     </Style>
     <Point>
'''
    code = code + '       <coordinates>' + str(coord[1]) + ',' + str(coord[2]) + ',0</coordinates>\n'
    code = code + '''     </Point>
   </Placemark>'''
    return code

















