tcx2ics 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tcx2ics-0.1.0/LICENSE +21 -0
- tcx2ics-0.1.0/PKG-INFO +60 -0
- tcx2ics-0.1.0/README.md +46 -0
- tcx2ics-0.1.0/pyproject.toml +16 -0
- tcx2ics-0.1.0/tcx2ics/__init__.py +3 -0
- tcx2ics-0.1.0/tcx2ics/tcx2ics.py +54 -0
tcx2ics-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Iztok Fister Jr.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tcx2ics-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: tcx2ics
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Generate ICS calendar events from TCX workout files
|
|
5
|
+
Author: Iztok Fister Jr.
|
|
6
|
+
Author-email: iztok@iztok.dev
|
|
7
|
+
Requires-Python: <4.0,>=3.12
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Requires-Dist: tcxreader (>=0.4.11,<0.5.0)
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# tcx2ics
|
|
15
|
+
|
|
16
|
+
Convert a `.tcx` activity file (from Garmin, Strava, etC.) into a single `.ics`
|
|
17
|
+
calendar event with basic workout Statistics.
|
|
18
|
+
|
|
19
|
+
The calendar event contains:
|
|
20
|
+
- start and end time of the activity
|
|
21
|
+
- sport type
|
|
22
|
+
- total duration
|
|
23
|
+
- total distance
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## 📦 Installation
|
|
27
|
+
|
|
28
|
+
### pip
|
|
29
|
+
|
|
30
|
+
Install tcx2ics with pip:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
pip install tcx2ics
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 🚀 Examples
|
|
37
|
+
|
|
38
|
+
### Basic example
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from tcx2ics import Tcx2Ics
|
|
42
|
+
Tcx2Ics().convert("15.tcx", "workout.ics")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 🔑 License
|
|
46
|
+
|
|
47
|
+
This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
|
|
48
|
+
|
|
49
|
+
## Disclaimer
|
|
50
|
+
|
|
51
|
+
This framework is provided as-is, and there are no guarantees that it fits your purposes or that it is bug-free. Use it at your own risk!
|
|
52
|
+
|
|
53
|
+
## 🔗 Related frameworks
|
|
54
|
+
|
|
55
|
+
[1] [AST-Monitor: A wearable Raspberry Pi computer for cyclists](https://github.com/firefly-cpp/AST-Monitor)
|
|
56
|
+
|
|
57
|
+
[2] [TCXReader.jl: Julia package designed for parsing TCX files](https://github.com/firefly-cpp/TCXReader.jl)
|
|
58
|
+
|
|
59
|
+
[3] [TCXWriter: A Tiny Library for writing/creating TCX files on Arduino](https://github.com/firefly-cpp/tcxwriter)
|
|
60
|
+
|
tcx2ics-0.1.0/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# tcx2ics
|
|
2
|
+
|
|
3
|
+
Convert a `.tcx` activity file (from Garmin, Strava, etC.) into a single `.ics`
|
|
4
|
+
calendar event with basic workout Statistics.
|
|
5
|
+
|
|
6
|
+
The calendar event contains:
|
|
7
|
+
- start and end time of the activity
|
|
8
|
+
- sport type
|
|
9
|
+
- total duration
|
|
10
|
+
- total distance
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## 📦 Installation
|
|
14
|
+
|
|
15
|
+
### pip
|
|
16
|
+
|
|
17
|
+
Install tcx2ics with pip:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
pip install tcx2ics
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 🚀 Examples
|
|
24
|
+
|
|
25
|
+
### Basic example
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from tcx2ics import Tcx2Ics
|
|
29
|
+
Tcx2Ics().convert("15.tcx", "workout.ics")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 🔑 License
|
|
33
|
+
|
|
34
|
+
This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
|
|
35
|
+
|
|
36
|
+
## Disclaimer
|
|
37
|
+
|
|
38
|
+
This framework is provided as-is, and there are no guarantees that it fits your purposes or that it is bug-free. Use it at your own risk!
|
|
39
|
+
|
|
40
|
+
## 🔗 Related frameworks
|
|
41
|
+
|
|
42
|
+
[1] [AST-Monitor: A wearable Raspberry Pi computer for cyclists](https://github.com/firefly-cpp/AST-Monitor)
|
|
43
|
+
|
|
44
|
+
[2] [TCXReader.jl: Julia package designed for parsing TCX files](https://github.com/firefly-cpp/TCXReader.jl)
|
|
45
|
+
|
|
46
|
+
[3] [TCXWriter: A Tiny Library for writing/creating TCX files on Arduino](https://github.com/firefly-cpp/tcxwriter)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tcx2ics"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Generate ICS calendar events from TCX workout files"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Iztok Fister Jr.",email = "iztok@iztok.dev"}
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = "<4.0,>=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"tcxreader (>=0.4.11,<0.5.0)"
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[build-system]
|
|
15
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
16
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from datetime import datetime, timedelta, timezone
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from tcxreader.tcxreader import TCXReader
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Tcx2Ics:
|
|
7
|
+
def __init__(self):
|
|
8
|
+
self.reader = TCXReader()
|
|
9
|
+
|
|
10
|
+
def convert(self, tcx_file: str, ics_file: str):
|
|
11
|
+
ex = self.reader.read(tcx_file)
|
|
12
|
+
|
|
13
|
+
sport = getattr(ex, "activity_type", None) or getattr(ex, "sport", None) or "Workout"
|
|
14
|
+
start = getattr(ex, "start_time", None)
|
|
15
|
+
duration = float(getattr(ex, "duration", 0) or 0) # seconds
|
|
16
|
+
distance = float(getattr(ex, "distance", 0) or 0) # meters
|
|
17
|
+
|
|
18
|
+
if not isinstance(start, datetime):
|
|
19
|
+
raise ValueError("No start_time found in TCX")
|
|
20
|
+
|
|
21
|
+
if start.tzinfo is None:
|
|
22
|
+
start = start.replace(tzinfo=timezone.utc)
|
|
23
|
+
else:
|
|
24
|
+
start = start.astimezone(timezone.utc)
|
|
25
|
+
|
|
26
|
+
end = start + timedelta(seconds=duration)
|
|
27
|
+
|
|
28
|
+
dist_km = distance / 1000.0
|
|
29
|
+
dur_h = int(duration) // 3600
|
|
30
|
+
dur_m = (int(duration) % 3600) // 60
|
|
31
|
+
dur_s = int(duration) % 60
|
|
32
|
+
|
|
33
|
+
summary = f"{sport} - {dist_km:.2f} km"
|
|
34
|
+
desc = f"Sport: {sport}\\nTotal duration: {dur_h}:{dur_m:02d}:{dur_s:02d}\\nDistance: {dist_km:.2f} km"
|
|
35
|
+
|
|
36
|
+
uid = f"{Path(tcx_file).stem}-{start.strftime('%Y%m%dT%H%M%SZ')}@tcx2ics"
|
|
37
|
+
now = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
|
38
|
+
|
|
39
|
+
ics = (
|
|
40
|
+
"BEGIN:VCALENDAR\r\n"
|
|
41
|
+
"VERSION:2.0\r\n"
|
|
42
|
+
"PRODID:-//tcx2ics//EN\r\n"
|
|
43
|
+
"BEGIN:VEVENT\r\n"
|
|
44
|
+
f"UID:{uid}\r\n"
|
|
45
|
+
f"DTSTAMP:{now}\r\n"
|
|
46
|
+
f"DTSTART:{start.strftime('%Y%m%dT%H%M%SZ')}\r\n"
|
|
47
|
+
f"DTEND:{end.strftime('%Y%m%dT%H%M%SZ')}\r\n"
|
|
48
|
+
f"SUMMARY:{summary}\r\n"
|
|
49
|
+
f"DESCRIPTION:{desc}\r\n"
|
|
50
|
+
"END:VEVENT\r\n"
|
|
51
|
+
"END:VCALENDAR\r\n"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
Path(ics_file).write_text(ics, encoding="utf-8")
|