aboutsummaryrefslogtreecommitdiff
path: root/fietsboek/convert.py
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2025-05-10 23:39:01 +0200
committerDaniel Schadt <kingdread@gmx.de>2025-05-10 23:39:01 +0200
commit8160afe6faf004aa0bc5478a0642a14eded3a914 (patch)
tree30a9e522a6c147624e18e3eb964fe4416ada3f88 /fietsboek/convert.py
parente699dba84378b71d4e0cd3de6f30a3a13b25a68d (diff)
downloadfietsboek-8160afe6faf004aa0bc5478a0642a14eded3a914.tar.gz
fietsboek-8160afe6faf004aa0bc5478a0642a14eded3a914.tar.bz2
fietsboek-8160afe6faf004aa0bc5478a0642a14eded3a914.zip
add button to exchange GPX track
Diffstat (limited to 'fietsboek/convert.py')
-rw-r--r--fietsboek/convert.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/fietsboek/convert.py b/fietsboek/convert.py
index 3c8208b..d3bfb22 100644
--- a/fietsboek/convert.py
+++ b/fietsboek/convert.py
@@ -49,4 +49,20 @@ def from_fit(data: bytes) -> GPX:
return gpx
-__all__ = ["from_fit"]
+def smart_convert(data: bytes) -> bytes:
+ """Tries to be smart in converting the input bytes.
+
+ This function automatically applies the correct conversion if possible.
+
+ Note that this function is not guaranteed to return valid GPX bytes. In the worst case,
+ invalid bytes are simply passed through.
+
+ :param data: The input bytes.
+ :return: The converted content.
+ """
+ if len(data) > 11 and data[9:12] == b"FIT":
+ return from_fit(data).to_xml().encode("utf-8")
+ return data
+
+
+__all__ = ["from_fit", "smart_convert"]