<s> import xml . dom . minidom as dom <EOL> from kml import kml <EOL> import json <EOL> import sys <EOL> import traceback <EOL> def kml_to_geojson ( kml_file , output_name ) : <EOL> kml_one = dom . parse ( kml_file ) <EOL> if not output_name . endswith ( "<STR_LIT>" ) : <EOL> output_name += "<STR_LIT>" <EOL> with open ( output_name , '<STR_LIT:w>' ) as outfile : <EOL> output = kml . build_feature_collection ( kml_one ) <EOL> json . dump ( output , outfile , indent = <NUM_LIT:4> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> if len ( sys . argv ) == <NUM_LIT:1> : <EOL> print "<STR_LIT>" <EOL> elif len ( sys . argv ) == <NUM_LIT:2> : <EOL> print "<STR_LIT>" , sys . argv [ <NUM_LIT:1> ] , "<STR_LIT>" <EOL> else : <EOL> input_kml = str ( sys . argv [ <NUM_LIT:1> ] ) <EOL> output_name = str ( sys . argv [ <NUM_LIT:2> ] ) <EOL> print "<STR_LIT>" , input_kml , "<STR_LIT:to>" , output_name + "<STR_LIT>" <EOL> kml_to_geojson ( input_kml , output_name ) <EOL> print "<STR_LIT>" <EOL> except : <EOL> error = sys . exc_info ( ) [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" , error , "<STR_LIT:\n>" <EOL> print traceback . format_exc ( ) </s>
