From d99a38e05f255a38cc6339a120255552567252b5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 30 Jun 2013 16:45:01 -0400 Subject: [PATCH] entry: Add Feed.get_geo for parsing the GEO field This is library-level code, so it should go in the library. --- pycalendar/entry.py | 10 ++++++++++ test/aggregate.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pycalendar/entry.py b/pycalendar/entry.py index 88a6b35..c0de990 100644 --- a/pycalendar/entry.py +++ b/pycalendar/entry.py @@ -207,5 +207,15 @@ class Entry (dict): value = self.get(*args, **kwargs) return _text.unescape(value) + def get_geo(self, key='GEO', *args, **kwargs): + """Get and unescape a GEO value + + As described in :RFC:`5545`, section 3.8.1.6 (Geographic + Position). + """ + value = self.get(key, *args, **kwargs) + lat,lon = [float(x) for x in value.split(';')] + return (lat, lon) + def write(self, stream): stream.write(self.content) diff --git a/test/aggregate.py b/test/aggregate.py index be97980..8c2a105 100755 --- a/test/aggregate.py +++ b/test/aggregate.py @@ -42,7 +42,7 @@ class Map (list): def add_event(self, event): if 'GEO' in event: - lat,lon = [float(x) for x in event['GEO'].split(';')] + lat,lon = event.get_geo() self.stream.write('{} at lat {}, lon {}\n'.format( event['UID'], lat, lon)) -- 2.26.2