Commits

Anonymous committed dd679be

final

Comments (0)

Files changed (5)

 import simplekml
 
 DOC_ROOT = 'http://stredovek.com/'
+STYLES = {
+    'hradiste': { 'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/blue.png'},
+    'hrady': { 'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/red.png'},
+    'rozhledny': { 'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/orange.png' },
+    'jine': { 'color': 'ffffffff', 'icon': 'http://maps.google.com/mapfiles/ms/micons/yellow.png' },
+}
+
 
 with open('places.pkl', 'rb') as f:
     places = pickle.load(f)
 
-
-#places = places[:5]
 #pprint.pprint(places)
 
-def fixurl(url):
-	idx = url.rfind('=')
-	return url[:idx] + '=' + urllib.quote(url[idx+1:])	
-
 def format_desc(place):
-	return '<img src="%s%s"><p>%s</p>' % (DOC_ROOT, place['image'], place['desc'])
+	desc = ['<p>', DOC_ROOT+place['url'], '</p>']
+	for img in place['images'][:3]:
+		desc.append('<img src="%s%s">' % (DOC_ROOT, img[0]))
+	desc.append(place['desc'])
+	return ''.join(desc)
 
 kml = simplekml.Kml()
-for place in places[5:10]:
-	url = fixurl(place['url']).replace('&', '&amp;')
-	kml.newpoint(
-		name=place['title'],
-		coords=[(place['lon'],place['lat'])],
-		description=format_desc(place),
-		atomlink=DOC_ROOT+url,
-	)
-kml.save("stredovek.kml")
+for (category, places) in places.iteritems():
+	style = simplekml.Style()
+	icon = simplekml.Icon(href=STYLES[category]['icon'])
+	color=STYLES[category]['color']
+	style.iconstyle = simplekml.IconStyle(icon=icon, color=color)
+	for place in places:
+		url = place['url'].replace('&', '&amp;')
+		point = kml.newpoint(
+			name=place['title'],
+			coords=[(place['lon'],place['lat'])],
+			description=format_desc(place),			
+			#atomlink=DOC_ROOT+url,
+		)
+		point.style = style
+
+kml.save("stredovek_com.kml")