262 | """
263 | kml_body = ""
264 |
265 | # Add paths where eclipse is total or annular
266 | for path in item['path']:
267 | point_string = generate_point_string(point_list=[point[1:3] for point in path[1]])
268 | kml_body += kml_template.kml_path.format(path_title="Central path, {}".format(item['event_month']),
269 | path_style="eclipseTotal" if path[0] else "eclipseAnnular",
270 | point_string=point_string)
271 |
272 | # Add contours
273 | for contour in item['contours']:
274 | if len(contour[1]) > 0:
275 | point_string = generate_point_string(point_list=[point[0:2] for point in contour[1]])
276 | kml_body += kml_template.kml_polygon.format(polygon_title=contour[0],
277 | polygon_style=(
278 | "eclipseOuter" if contour[0] == "Partial eclipse"
279 | else "eclipseInner"),
280 | point_string=point_string)
281 |
282 | # Write KMZ output
283 | file_stub = os.path.split(item['filename'])[1][:-5]
284 | filename = os.path.join(out_path, "{}.kmz".format(file_stub))
285 | with zipfile.ZipFile(filename, "w", zipfile.ZIP_DEFLATED) as myzip:
286 | kml_filename = "{}.kml".format(file_stub)
287 | with myzip.open(kml_filename, "w") as f:
288 | f.write(kml_template.kml_document.format(
289 | title=event_title,
290 | description=event_description,
291 | body=kml_body
292 | ).encode('utf-8'))
293 |
294 |
295 | # Do it right away if we're run as a script
296 | if __name__ == "__main__":
297 | logging.basicConfig(level=logging.INFO,
298 | stream=sys.stdout,
299 | format='[%(asctime)s] %(levelname)s:%(filename)s:%(message)s',
300 | datefmt='%d/%m/%Y %H:%M:%S')
301 | logger = logging.getLogger(__name__)
302 | logger.info(__doc__.strip())
303 |
304 | make_kml()
305 |
--------------------------------------------------------------------------------