TypeError: can't compare offset-naive and offset-aware datetimes
lowtower opened this issue · comments
I try to generate a poster with some gpx files extracted from my garmin account.
I have downloaded the files using the proposed python script garmin-connect-export.
Now, I get the following error:
Traceback (most recent call last):
File "~/GpxTrackPoster/venv/bin/create_poster", line 8, in <module>
sys.exit(main())
File "~/GpxTrackPoster/venv/lib/python3.7/site-packages/gpxtrackposter/cli.py", line 217, in main
tracks = loader.load_tracks(args.gpx_dir)
File "~/GpxTrackPoster/venv/lib/python3.7/site-packages/gpxtrackposter/track_loader.py", line 114, in load_tracks
return self._filter_and_merge_tracks(tracks)
File "~/GpxTrackPoster/venv/lib/python3.7/site-packages/gpxtrackposter/track_loader.py", line 169, in _filter_and_merge_tracks
tracks = self._merge_tracks(tracks)
File "~/GpxTrackPoster/venv/lib/python3.7/site-packages/gpxtrackposter/track_loader.py", line 176, in _merge_tracks
tracks = sorted(tracks, key=lambda t1: t1.start_time())
TypeError: can't compare offset-naive and offset-aware datetimes
Is something wrong with my gpx files?
As said, they all come from the same source.
Thanks in advance,
LT.
Can you add this line in file timezone_adjuster.py
for test? and try again.
I am thinking some gpx we can not get tz_name info.
time.replace(tzinfo=timezone.utc)
also need to add import line
from datetime import timezone
from datetime import timezone
class TimezoneAdjuster:
_timezonefinder: typing.Optional[timezonefinder.TimezoneFinder] = None
def __init__(self) -> None:
if not TimezoneAdjuster._timezonefinder:
TimezoneAdjuster._timezonefinder = timezonefinder.TimezoneFinder()
@classmethod
def adjust(cls, time: datetime.datetime, latlng: s2sphere.LatLng) -> datetime.datetime:
# If a timezone is set, there's nothing to do.
if time.utcoffset():
return time
assert cls._timezonefinder
tz_name = cls._timezonefinder.timezone_at(lat=latlng.lat().degrees, lng=latlng.lng().degrees)
if tz_name is None:
time.replace(tzinfo=timezone.utc)
return time
tz = pytz.timezone(tz_name)
tz_time = time.astimezone(tz)
return tz_time
Thanks for Your quick reply!
The modification did work!
I get some errors for only a few gpx files such as:
Error while loading ~/2020/activity_5702364393.gpx: Track has no start or end time.
I have to have a closer look at these files.
Thanks a lot,
cheers,
LT
Thanks for Your quick reply!
The modification did work!
I get some errors for only a few gpx files such as:Error while loading ~/2020/activity_5702364393.gpx: Track has no start or end time.
I have to have a closer look at these files.
Thanks a lot,
cheers,
LT
Maybe this gpx has something wrong, you can open it to see if it contains info or not.
You can delete the activity_5702364393.gpx file from the folder to see what happens.
If you have other gpx files like this, maybe you need to delete them too.
I checked the relevant gpx files - they were not "running" files but "cardio" without time info - so the error messages are reasonable.
Thanks for Your help and filing the pr!