2 # -*- coding: utf-8 -*-
4 from __future__ import division
6 from datetime import datetime, timedelta
11 #from optparse import OptionParser
12 #parser = OptionParser()
13 #options, args = parser.parse_args()
15 cursor = get_common_cursor()
17 print '<?xml version="1.0" encoding=\"UTF-8\"?>'
18 print '<kml xmlns="http://earth.google.com/kml/2.1">'
20 print '<name>BTF spotters</name>'
22 def print_style(name,icon,heading=None):
24 if heading is not None:
25 stylename+='-'+str(heading)
26 print '<Style id="%s">' % stylename
28 print ' <scale>0.7</scale>'
29 print ' </LabelStyle>'
32 print ' <href>%s</href>' % icon
34 if heading is not None:
35 print ' <heading>%d</heading>' % heading
36 print ' <scale>0.5</scale>'
37 print ' <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>'
41 print_style('plane', 'plane.png')
44 SELECT reg, ads, type, flight, plane.usr, updated, lat, lon
47 ON (plane.usr = ppuser.usr)
53 for reg, ads, type, flight, usr, updated, latitude, longitude in cursor.fetchall():
54 if not latitude or not longitude:
58 return txt.encode('utf8').replace('<', '<')
70 print '<description><![CDATA['
71 print 'Last seen: %s<br/>' % str(updated)
72 print 'ADS:', ads, '<br/>'
73 print 'Plane type:', type, '<br/>'
74 print 'Flight:', flight, '<br/>'
75 print "Warning, position is a wild guess! It's computed by averaging the positions broadcasted by other planes and received by the same ground station.<br/>"
77 print '</description>'
80 print '<styleUrl>#%s</styleUrl>' % style
83 print '<altitudeMode>relativeToGround</altitudeMode>'
84 print '<coordinates>'+str(longitude)+','+str(latitude)+',0</coordinates>'
91 if __name__ == "__main__":