Updates and fixes
* XML tag <Navs/> formatted like in native CNX (<Navs />); * Added end delimiter for 'Tracks' array as in native CNX; * Fixed encoding for log output.
This commit is contained in:
@@ -59,7 +59,7 @@ class GPX2CNX:
|
||||
textinfo = ""
|
||||
flogout = 0
|
||||
try:
|
||||
with open("log.txt", "r") as logtxt:
|
||||
with open("log.txt", "r", encoding="utf-8") as logtxt:
|
||||
textinfo = logtxt.read()
|
||||
flogout = 1
|
||||
except FileNotFoundError:
|
||||
@@ -107,7 +107,6 @@ class GPX2CNX:
|
||||
if not os.path.exists(output_dir):
|
||||
os.makedirs(output_dir)
|
||||
|
||||
log = "gpx2cnx.py log"
|
||||
self.results = []
|
||||
for gpx_file in gpx_files:
|
||||
try:
|
||||
@@ -216,7 +215,8 @@ class GPX2CNX:
|
||||
|
||||
if relative_points:
|
||||
tracks_str = ';'.join(relative_points)
|
||||
ET.SubElement(route, 'Tracks').text = tracks_str
|
||||
format_tracks_str = tracks_str + ';' # Line-ending delimiter as in native CNX
|
||||
ET.SubElement(route, 'Tracks').text = format_tracks_str
|
||||
else:
|
||||
ET.SubElement(route, 'Tracks').text = ""
|
||||
|
||||
@@ -235,9 +235,10 @@ class GPX2CNX:
|
||||
trim_filename = filename[:18]
|
||||
output_filename = os.path.join(output_dir, f"route_{trim_filename}.cnx")
|
||||
xml_string = self.prettify(route)
|
||||
format_xml_string = xml_string.replace("<Navs/>", "<Navs />") # Format the XML tag like in native CNX
|
||||
with codecs.open(output_filename, "w", encoding='utf-8-sig') as f:
|
||||
f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')
|
||||
f.write(xml_string[xml_string.find('<Route'):])
|
||||
f.write(format_xml_string[format_xml_string.find('<Route'):])
|
||||
|
||||
self.results.append(f"-- {gpx_file} -> SUCCESS")
|
||||
self.rstat = 1
|
||||
|
||||
Reference in New Issue
Block a user