Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vGeo documentation #769

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Changelog

Minor changes:

- Add a ``weekday`` attribute to ``vWeekday`` components. See `Issue 749 <https://github.com/collective/icalendar/issues/749>`_.
- Document ``vRecur`` property. See `Issue 758 <https://github.com/collective/icalendar/issues/758>`_.
- Add a ``weekday`` attribute to :class:`icalendar.prop.vWeekday` components. See `Issue 749 <https://github.com/collective/icalendar/issues/749>`_.
- Document :class:`icalendar.prop.vRecur` property. See `Issue 758 <https://github.com/collective/icalendar/issues/758>`_.
- Print failure of doctest to aid debugging.
- Improve documentation of :class:`icalendar.prop.vGeo`
- Fix tests, improve code readability, fix typing. See `Issue 766 <https://github.com/collective/icalendar/issues/766>`_ and `Issue 765 <https://github.com/collective/icalendar/issues/765>`_.

Breaking changes:
Expand Down
38 changes: 30 additions & 8 deletions src/icalendar/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,40 +1478,62 @@ class vGeo:

GEO:37.386013;-122.082932

Parse vGeo:

.. code-block:: pycon

>>> from icalendar.prop import vGeo
>>> geo = vGeo.from_ical('37.386013;-122.082932')
>>> geo
(37.386013, -122.082932)

Add a geo location to an event:

.. code-block:: pycon

>>> from icalendar import Event
>>> event = Event()
>>> latitude = 37.386013
>>> longitude = -122.082932
>>> event.add('GEO', (latitude, longitude))
>>> event['GEO']
vGeo((37.386013, -122.082932))
"""

def __init__(self, geo):
def __init__(self, geo: tuple[float|str|int, float|str|int]):
"""Create a new vGeo from a tuple of (latitude, longitude).

Raises:
ValueError: if geo is not a tuple of (latitude, longitude)
"""
try:
latitude, longitude = (geo[0], geo[1])
latitude = float(latitude)
longitude = float(longitude)
except Exception:
raise ValueError('Input must be (float, float) for '
'latitude and longitude')
except Exception as e:
raise ValueError("Input must be (float, float) for "
"latitude and longitude") from e
self.latitude = latitude
self.longitude = longitude
self.params = Parameters()

def to_ical(self):
return f'{self.latitude};{self.longitude}'
return f"{self.latitude};{self.longitude}"

@staticmethod
def from_ical(ical):
try:
latitude, longitude = ical.split(';')
latitude, longitude = ical.split(";")
return (float(latitude), float(longitude))
except Exception:
raise ValueError(f"Expected 'float;float' , got: {ical}")
except Exception as e:
raise ValueError(f"Expected 'float;float' , got: {ical}") from e

def __eq__(self, other):
return self.to_ical() == other.to_ical()

def __repr__(self):
"""repr(self)"""
return f"{self.__class__.__name__}(({self.latitude}, {self.longitude}))"

class vUTCOffset:
"""UTC Offset
Expand Down
Loading