polarsteps-data-parser 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- polarsteps_data_parser/__main__.py +74 -74
- polarsteps_data_parser/model.py +147 -147
- polarsteps_data_parser/pdf_generator.py +155 -155
- polarsteps_data_parser/retrieve_step_comments.py +135 -135
- polarsteps_data_parser/utils.py +71 -71
- {polarsteps_data_parser-0.1.0.dist-info → polarsteps_data_parser-0.1.1.dist-info}/METADATA +15 -25
- polarsteps_data_parser-0.1.1.dist-info/RECORD +10 -0
- polarsteps_data_parser-0.1.1.dist-info/licenses/LICENSE +21 -0
- polarsteps_data_parser-0.1.0.dist-info/RECORD +0 -10
- polarsteps_data_parser-0.1.0.dist-info/licenses/LICENSE +0 -674
- {polarsteps_data_parser-0.1.0.dist-info → polarsteps_data_parser-0.1.1.dist-info}/WHEEL +0 -0
- {polarsteps_data_parser-0.1.0.dist-info → polarsteps_data_parser-0.1.1.dist-info}/entry_points.txt +0 -0
polarsteps_data_parser/utils.py
CHANGED
@@ -1,71 +1,71 @@
|
|
1
|
-
import json
|
2
|
-
from datetime import datetime
|
3
|
-
from pathlib import Path
|
4
|
-
|
5
|
-
import click
|
6
|
-
|
7
|
-
|
8
|
-
def load_json_from_file(path: Path) -> dict:
|
9
|
-
"""Load content from file and convert to JSON object.
|
10
|
-
|
11
|
-
Args:
|
12
|
-
path: path to file
|
13
|
-
|
14
|
-
Returns:
|
15
|
-
dict: parsed JSON
|
16
|
-
"""
|
17
|
-
with open(path, "r") as file:
|
18
|
-
return json.load(file)
|
19
|
-
|
20
|
-
|
21
|
-
def parse_date(date: str) -> datetime:
|
22
|
-
"""Convert a string containing a timestamp to a datetime object.
|
23
|
-
|
24
|
-
Args:
|
25
|
-
date: unix timestamp
|
26
|
-
|
27
|
-
Returns:
|
28
|
-
datetime: timestamp parsed to a datetime object
|
29
|
-
|
30
|
-
"""
|
31
|
-
timestamp = float(date)
|
32
|
-
date_time = datetime.fromtimestamp(timestamp)
|
33
|
-
return date_time
|
34
|
-
|
35
|
-
|
36
|
-
def find_folder_by_id(folder_id: str) -> Path | None:
|
37
|
-
"""Finds and returns the path of a folder within the base_directory that matches the given folder_id.
|
38
|
-
|
39
|
-
Args:
|
40
|
-
folder_id (str): The ID to search for in the folder names.
|
41
|
-
|
42
|
-
Returns:
|
43
|
-
Path or None: The path of the matching folder, or None if no matching folder is found.
|
44
|
-
"""
|
45
|
-
base_path = Path(click.get_current_context().params["input_folder"])
|
46
|
-
|
47
|
-
for folder in base_path.iterdir():
|
48
|
-
if folder.is_dir() and folder.name.endswith(f"_{folder_id}"):
|
49
|
-
return folder
|
50
|
-
return None
|
51
|
-
|
52
|
-
|
53
|
-
def list_files_in_folder(folder_path: Path, dir_has_to_exist: bool = True) -> list[Path]:
|
54
|
-
"""List all files in the given folder.
|
55
|
-
|
56
|
-
Args:
|
57
|
-
folder_path (str or Path): The path of the folder to list files from.
|
58
|
-
dir_has_to_exist (bool): raise exception if path does not exist.
|
59
|
-
|
60
|
-
Returns:
|
61
|
-
List[Path]: A list of Path objects representing the files in the folder.
|
62
|
-
|
63
|
-
"""
|
64
|
-
folder = Path(folder_path)
|
65
|
-
|
66
|
-
if not folder.is_dir():
|
67
|
-
if dir_has_to_exist:
|
68
|
-
raise NotADirectoryError(f"{folder_path} is not a valid directory")
|
69
|
-
return []
|
70
|
-
|
71
|
-
return [file for file in folder.iterdir() if file.is_file()]
|
1
|
+
import json
|
2
|
+
from datetime import datetime
|
3
|
+
from pathlib import Path
|
4
|
+
|
5
|
+
import click
|
6
|
+
|
7
|
+
|
8
|
+
def load_json_from_file(path: Path) -> dict:
|
9
|
+
"""Load content from file and convert to JSON object.
|
10
|
+
|
11
|
+
Args:
|
12
|
+
path: path to file
|
13
|
+
|
14
|
+
Returns:
|
15
|
+
dict: parsed JSON
|
16
|
+
"""
|
17
|
+
with open(path, "r") as file:
|
18
|
+
return json.load(file)
|
19
|
+
|
20
|
+
|
21
|
+
def parse_date(date: str) -> datetime:
|
22
|
+
"""Convert a string containing a timestamp to a datetime object.
|
23
|
+
|
24
|
+
Args:
|
25
|
+
date: unix timestamp
|
26
|
+
|
27
|
+
Returns:
|
28
|
+
datetime: timestamp parsed to a datetime object
|
29
|
+
|
30
|
+
"""
|
31
|
+
timestamp = float(date)
|
32
|
+
date_time = datetime.fromtimestamp(timestamp)
|
33
|
+
return date_time
|
34
|
+
|
35
|
+
|
36
|
+
def find_folder_by_id(folder_id: str) -> Path | None:
|
37
|
+
"""Finds and returns the path of a folder within the base_directory that matches the given folder_id.
|
38
|
+
|
39
|
+
Args:
|
40
|
+
folder_id (str): The ID to search for in the folder names.
|
41
|
+
|
42
|
+
Returns:
|
43
|
+
Path or None: The path of the matching folder, or None if no matching folder is found.
|
44
|
+
"""
|
45
|
+
base_path = Path(click.get_current_context().params["input_folder"])
|
46
|
+
|
47
|
+
for folder in base_path.iterdir():
|
48
|
+
if folder.is_dir() and folder.name.endswith(f"_{folder_id}"):
|
49
|
+
return folder
|
50
|
+
return None
|
51
|
+
|
52
|
+
|
53
|
+
def list_files_in_folder(folder_path: Path, dir_has_to_exist: bool = True) -> list[Path]:
|
54
|
+
"""List all files in the given folder.
|
55
|
+
|
56
|
+
Args:
|
57
|
+
folder_path (str or Path): The path of the folder to list files from.
|
58
|
+
dir_has_to_exist (bool): raise exception if path does not exist.
|
59
|
+
|
60
|
+
Returns:
|
61
|
+
List[Path]: A list of Path objects representing the files in the folder.
|
62
|
+
|
63
|
+
"""
|
64
|
+
folder = Path(folder_path)
|
65
|
+
|
66
|
+
if not folder.is_dir():
|
67
|
+
if dir_has_to_exist:
|
68
|
+
raise NotADirectoryError(f"{folder_path} is not a valid directory")
|
69
|
+
return []
|
70
|
+
|
71
|
+
return [file for file in folder.iterdir() if file.is_file()]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: polarsteps-data-parser
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.1
|
4
4
|
Summary: Parse and extract data from the data export of travel tracking app Polarsteps.
|
5
5
|
Author-email: Niek van Leeuwen <ik@niekvanleeuwen.nl>
|
6
6
|
License-Expression: MIT
|
@@ -24,44 +24,34 @@ Tool designed to parse and extract data from the travel tracking app [Polarsteps
|
|
24
24
|
## Getting started
|
25
25
|
|
26
26
|
### Installation
|
27
|
-
To set up the project, ensure you have Python 3.11+ installed.
|
28
|
-
|
29
|
-
Clone the repository:
|
30
|
-
|
31
|
-
```shell
|
32
|
-
git clone https://github.com/niekvleeuwen/polarsteps-data-parser.git
|
33
|
-
cd polarsteps-trip-analyzer
|
34
|
-
```
|
35
|
-
|
36
|
-
Ensure poetry is available, e.g. on Ubuntu/Debian you can run the following:
|
27
|
+
To set up the project, ensure you have Python 3.11+ installed.
|
37
28
|
|
29
|
+
Install from PyPI using pip:
|
38
30
|
```shell
|
39
|
-
|
31
|
+
pip install polarsteps-data-parser
|
40
32
|
```
|
41
33
|
|
42
|
-
|
34
|
+
### Usage
|
35
|
+
To get the following output, run `polarsteps-data-parser --help`.
|
43
36
|
|
44
37
|
```shell
|
45
|
-
|
46
|
-
```
|
47
|
-
|
48
|
-
Then enter the created virtual environment:
|
38
|
+
Usage: polarsteps-data-parser [OPTIONS] INPUT_FOLDER
|
49
39
|
|
50
|
-
|
51
|
-
poetry shell
|
52
|
-
```
|
40
|
+
Parse the data from a Polarsteps trip export.
|
53
41
|
|
54
|
-
|
55
|
-
|
42
|
+
INPUT_FOLDER should contain the Polarsteps data export of one (!) trip. Make
|
43
|
+
sure the folder contains a `trip.json` and `locations.json`.
|
56
44
|
|
57
|
-
|
58
|
-
|
45
|
+
Options:
|
46
|
+
--output TEXT Output PDF file name [default: Trip report.pdf]
|
47
|
+
--enrich-with-comments Whether to enrich the trip with comments or not.
|
48
|
+
--help Show this message and exit.
|
59
49
|
```
|
60
50
|
|
61
51
|
For example, to load and analyse a trip with the data located in the `./data/trip1` folder and enrich the trip with comments, use the following command:
|
62
52
|
|
63
53
|
```shell
|
64
|
-
polarsteps-data-parser
|
54
|
+
polarsteps-data-parser ./data/trip1 --enrich-with-comments
|
65
55
|
```
|
66
56
|
|
67
57
|
## Disclaimer
|
@@ -0,0 +1,10 @@
|
|
1
|
+
polarsteps_data_parser/__main__.py,sha256=rn-Yz_5KAXsCrsu5LjQLHFFEqc4sKxhSpcHgvnjlNxk,2419
|
2
|
+
polarsteps_data_parser/model.py,sha256=v8hSCWRs82_Hur5EnsSETcQCv06LPx0lOgFo478CwrU,3704
|
3
|
+
polarsteps_data_parser/pdf_generator.py,sha256=Neiz96urBlLOXJ80MDTYmlMX-mYOwuaW7QVHokVAJis,5510
|
4
|
+
polarsteps_data_parser/retrieve_step_comments.py,sha256=AVcgZ_0iG91CKCHwgLjX7YfeVpa4P2XZ0GchPTbzZGs,3970
|
5
|
+
polarsteps_data_parser/utils.py,sha256=_PKy-5VFEEtPXQtNyxogs1GZqPr_16cpLMtfTc75skM,1901
|
6
|
+
polarsteps_data_parser-0.1.1.dist-info/METADATA,sha256=Zo0TkxYSAUYi2060qFVsEnzJTfewE1iKeX2POttP3d8,2626
|
7
|
+
polarsteps_data_parser-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
8
|
+
polarsteps_data_parser-0.1.1.dist-info/entry_points.txt,sha256=UyGRCnpI13JtHPVilcSVgUSDNEYyv8-EQWgiJm-_ABg,79
|
9
|
+
polarsteps_data_parser-0.1.1.dist-info/licenses/LICENSE,sha256=hxqP9qEfnLOSMQQMvUWQ4g-GOG6pny7O0_9AExvE-xU,1072
|
10
|
+
polarsteps_data_parser-0.1.1.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Niek van Leeuwen
|
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.
|
@@ -1,10 +0,0 @@
|
|
1
|
-
polarsteps_data_parser/__main__.py,sha256=LgDdFfqviXCKd9ytERb3cGxgyNJ5hY6pYg1Y20SUIJA,2493
|
2
|
-
polarsteps_data_parser/model.py,sha256=8-ekrANj-SV_AafWwS_kmPqNoFTMZXpj7Mb1X-kpXwA,3851
|
3
|
-
polarsteps_data_parser/pdf_generator.py,sha256=WX50wR5lPNaAHz9830zqxkqlBIaBZ3YkzKNRZ4VMXxc,5665
|
4
|
-
polarsteps_data_parser/retrieve_step_comments.py,sha256=oTaAT05vl-bFrICE5TId0OV2gCKQH3iLkrKFCiSpk7g,4105
|
5
|
-
polarsteps_data_parser/utils.py,sha256=K5TYZIZEMEv4p332h6zDLA5rdpslARbHw7bCJ9Os45k,1972
|
6
|
-
polarsteps_data_parser-0.1.0.dist-info/METADATA,sha256=2OUrp2m30N2X41TXintN0GTR8aOVo61cS_f-q1Jt1FI,2527
|
7
|
-
polarsteps_data_parser-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
8
|
-
polarsteps_data_parser-0.1.0.dist-info/entry_points.txt,sha256=UyGRCnpI13JtHPVilcSVgUSDNEYyv8-EQWgiJm-_ABg,79
|
9
|
-
polarsteps_data_parser-0.1.0.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
|
10
|
-
polarsteps_data_parser-0.1.0.dist-info/RECORD,,
|