def write_kml_output(self, ships, out_name): """ saves a summary of all selected ships in KML format (or KMZ if gzip option selected) out_name is used to compute the output filename returns filename """ # create an instance of the KML class kml = KML() # send it the `contents` method to retrieve the text # to be written in the kml file contents = kml.contents( ships, kml_name=out_name, description=f"Positions for ship(s) {out_name}") # compute suffix based on self.args.gzip # - whether the --gzip option was passed or not suffix = "kmz" if self.args.gzip else "kml" # compute full filename kml_filename = f"{out_name}.{suffix}" # message print(f"Opening {kml_filename} for ship {out_name}") # open a plain file or compressed file as requested with gzip.open(kml_filename, 'w', newline="\n") if self.args.gzip \ else open(kml_filename, 'w', newline="\n") as out: out.write(contents) # return filename return kml_filename
def write_kml_output(self, ships, out_name): """ saves a summary of all selected ships in KML format (or KMZ if gzip option selected) out_name is used to compute the output filename returns filename """ # create an instance of the KML class kml = KML() # send it the `contents` method to retrieve the text # to be written in the kml file contents = kml.contents(ships, kml_name=out_name, description = "Positions for ship(s) {}".\ format(out_name) ) # compute suffix based on self.args.gzip # - whether the --gzip option was passed or not suffix = "kmz" if self.args.gzip else "kml" # compute full filename kml_filename = "{}.{}".format(out_name, suffix) # message print ("Opening {kml_filename} for ship {out_name}".\ format(**locals())) # open a plain file or compressed file as requested with gzip.open(kml_filename, 'w') if self.args.gzip \ else open(kml_filename, 'w') as out: out.write(contents) # return filename return kml_filename