# HG changeset patch # User Paul Boddie # Date 1312673024 -7200 # Node ID 3a366104152eb0002e81039ec4f9a2c3468cec4c # Parent f6fa1badce5fb46b05edf3d3239183954e3d62c8 Added support for explicit latitude and longitude event properties. diff -r f6fa1badce5f -r 3a366104152e EventAggregatorSupport.py --- a/EventAggregatorSupport.py Sun Aug 07 00:11:31 2011 +0200 +++ b/EventAggregatorSupport.py Sun Aug 07 01:23:44 2011 +0200 @@ -148,6 +148,9 @@ else: return int(x) +def to_list(s, sep): + return [x.strip() for x in s.split(sep) if x.strip()] + def sort_none_first(x, y): if x is None: return -1 @@ -613,7 +616,12 @@ # Convert lists. elif property == "CATEGORIES": - value = [v.strip() for v in value.split(",") if v.strip()] + value = to_list(value, ",") + + # Convert positions (using decimal values). + + elif property == "GEO": + value = map(getMapReferenceFromDecimal, to_list(value, ";")) # Accept other textual data as it is. @@ -634,7 +642,7 @@ class EventPage: - "An event page." + "An event page acting as an event resource." def __init__(self, page): self.page = page @@ -754,7 +762,12 @@ # Lists (whose elements may be quoted). elif term in ("topics", "categories"): - desc = [getSimpleWikiText(value.strip()) for value in desc.split(",") if value.strip()] + desc = map(getSimpleWikiText, to_list(desc, ",")) + + # Position details (using degrees:minutes:seconds). + + elif term == "geo": + desc = map(getMapReference, to_list(desc, ";")) # Labels which may well be quoted. @@ -2422,6 +2435,15 @@ return Reference(*map(float, value.split(":"))) +def getMapReferenceFromDecimal(value): + + "Return a map reference by parsing the given 'value' in decimal degrees." + + value = float(value) + degrees, remainder = divmod(abs(value * 3600), 3600) + minutes, seconds = divmod(remainder, 60) + return Reference(sign(value) * degrees, minutes, seconds) + # vim: tabstop=4 expandtab shiftwidth=4 # User interface functions. diff -r f6fa1badce5f -r 3a366104152e actions/EventAggregatorSummary.py --- a/actions/EventAggregatorSummary.py Sun Aug 07 00:11:31 2011 +0200 +++ b/actions/EventAggregatorSummary.py Sun Aug 07 01:23:44 2011 +0200 @@ -372,6 +372,8 @@ )) if event_details.has_key("location"): request.write("LOCATION:%s\r\n" % getQuotedText(event_details["location"])) + if event_details.has_key("geo"): + request.write("GEO:%s\r\n" % getQuotedText(";".join([str(ref.to_degrees()) for ref in event_details["geo"]]))) request.write("END:VEVENT\r\n") diff -r f6fa1badce5f -r 3a366104152e macros/EventAggregator.py --- a/macros/EventAggregator.py Sun Aug 07 00:11:31 2011 +0200 +++ b/macros/EventAggregator.py Sun Aug 07 01:23:44 2011 +0200 @@ -1583,9 +1583,16 @@ if location is not None and not event_locations.has_key(location): - # Look up the position of a location using the locations page. - - latitude, longitude = getLocationPosition(location, locations) + # Get any explicit position of an event. + + if event_details.has_key("geo"): + latitude, longitude = event_details["geo"] + + # Or look up the position of a location using the locations + # page. + + else: + latitude, longitude = getLocationPosition(location, locations) # Use a normalised location if necessary. @@ -1598,6 +1605,8 @@ event_locations[location] = latitude, longitude + # Record events according to location. + if not events_by_location.has_key(location): events_by_location[location] = []