entry: Add Feed.get_geo for parsing the GEO field
authorW. Trevor King <wking@tremily.us>
Sun, 30 Jun 2013 20:45:01 +0000 (16:45 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 30 Jun 2013 20:45:01 +0000 (16:45 -0400)
This is library-level code, so it should go in the library.

pycalendar/entry.py
test/aggregate.py

index 88a6b359b48f9a8c4932eecd31e161c23834b11a..c0de9902c82645a306194242f1b64fd16096fa3c 100644 (file)
@@ -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)
index be97980f74f055c77b3d48fbe84025525f64194a..8c2a105fe0c81ba4fdb6d6943bf7f66c7989ab51 100755 (executable)
@@ -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))