Hi How can I improve this KML generator? We discussed pre-generating the output like a cron job perhaps saving a blob to blobstore since it can't serve many markers like this. Can you recommend me how to proceed? Is the bottleneck where using images?
class KML(webapp.RequestHandler):#get max, make static or cron job save file like blob
def get(self):
from django.template import defaultfilters
start=datetime.datetime.now()-timedelta(days=150)#vary
host = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"])
#count = 22
count = int(self.request.get('count')) if not self.request.get('count')=='' else 50
a= A.all().filter("modified >", start).filter("published =", True).order("-modified").fetch(count)
self.response.out.write('<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"><Document>')
for a in a:
if a.geopt:
image = a.matched_images.get()
if image:
imageid=image.key().id()
kml = ('<Placemark><name></name><description><![CDATA[<img src="http://%s/images/%d.%s"> %s ]]></description><Style><IconStyle><Icon><href>http://www.google.com/intl/en_us/mapfiles/ms/icons/green-dot.png</href></Icon></IconStyle></Style><Point><coordinates>%d,%d</coordinates></Point></Placemark>'
) %(host,image.key().id(),image.full_ext,'<a href="http://'+host+'/'+str(a.key().id())+'">'+a.title+'</a><br/>'+defaultfilters.urlize( defaultfilters.truncatewords( a.text , 20 ) ),a.geopt.lon,a.geopt.lat)
else:
kml = ('<Placemark><name></name><description><![CDATA[%s]]></description><Style><IconStyle><Icon><href>http://www.google.com/intl/en_us/mapfiles/ms/icons/green-dot.png</href></Icon></IconStyle></Style> <Point><coordinates>%d,%d</coordinates></Point></Placemark>'
) %('<a href="http://'+host+'/'+str(a.key().id())+'">'+a.title+'</a><br/>'+defaultfilters.urlize( defaultfilters.truncatewords( defaultfilters.striptags( a.text ) , 20 ) ),a.geopt.lon,a.geopt.lat)
self.response.out.write(kml)
self.response.out.write( '</Document></kml>')