1.1 --- a/EventAggregatorSupport.py Sun Aug 07 00:11:31 2011 +0200
1.2 +++ b/EventAggregatorSupport.py Sun Aug 07 01:23:44 2011 +0200
1.3 @@ -148,6 +148,9 @@
1.4 else:
1.5 return int(x)
1.6
1.7 +def to_list(s, sep):
1.8 + return [x.strip() for x in s.split(sep) if x.strip()]
1.9 +
1.10 def sort_none_first(x, y):
1.11 if x is None:
1.12 return -1
1.13 @@ -613,7 +616,12 @@
1.14 # Convert lists.
1.15
1.16 elif property == "CATEGORIES":
1.17 - value = [v.strip() for v in value.split(",") if v.strip()]
1.18 + value = to_list(value, ",")
1.19 +
1.20 + # Convert positions (using decimal values).
1.21 +
1.22 + elif property == "GEO":
1.23 + value = map(getMapReferenceFromDecimal, to_list(value, ";"))
1.24
1.25 # Accept other textual data as it is.
1.26
1.27 @@ -634,7 +642,7 @@
1.28
1.29 class EventPage:
1.30
1.31 - "An event page."
1.32 + "An event page acting as an event resource."
1.33
1.34 def __init__(self, page):
1.35 self.page = page
1.36 @@ -754,7 +762,12 @@
1.37 # Lists (whose elements may be quoted).
1.38
1.39 elif term in ("topics", "categories"):
1.40 - desc = [getSimpleWikiText(value.strip()) for value in desc.split(",") if value.strip()]
1.41 + desc = map(getSimpleWikiText, to_list(desc, ","))
1.42 +
1.43 + # Position details (using degrees:minutes:seconds).
1.44 +
1.45 + elif term == "geo":
1.46 + desc = map(getMapReference, to_list(desc, ";"))
1.47
1.48 # Labels which may well be quoted.
1.49
1.50 @@ -2422,6 +2435,15 @@
1.51
1.52 return Reference(*map(float, value.split(":")))
1.53
1.54 +def getMapReferenceFromDecimal(value):
1.55 +
1.56 + "Return a map reference by parsing the given 'value' in decimal degrees."
1.57 +
1.58 + value = float(value)
1.59 + degrees, remainder = divmod(abs(value * 3600), 3600)
1.60 + minutes, seconds = divmod(remainder, 60)
1.61 + return Reference(sign(value) * degrees, minutes, seconds)
1.62 +
1.63 # vim: tabstop=4 expandtab shiftwidth=4
1.64
1.65 # User interface functions.
2.1 --- a/actions/EventAggregatorSummary.py Sun Aug 07 00:11:31 2011 +0200
2.2 +++ b/actions/EventAggregatorSummary.py Sun Aug 07 01:23:44 2011 +0200
2.3 @@ -372,6 +372,8 @@
2.4 ))
2.5 if event_details.has_key("location"):
2.6 request.write("LOCATION:%s\r\n" % getQuotedText(event_details["location"]))
2.7 + if event_details.has_key("geo"):
2.8 + request.write("GEO:%s\r\n" % getQuotedText(";".join([str(ref.to_degrees()) for ref in event_details["geo"]])))
2.9
2.10 request.write("END:VEVENT\r\n")
2.11
3.1 --- a/macros/EventAggregator.py Sun Aug 07 00:11:31 2011 +0200
3.2 +++ b/macros/EventAggregator.py Sun Aug 07 01:23:44 2011 +0200
3.3 @@ -1583,9 +1583,16 @@
3.4
3.5 if location is not None and not event_locations.has_key(location):
3.6
3.7 - # Look up the position of a location using the locations page.
3.8 -
3.9 - latitude, longitude = getLocationPosition(location, locations)
3.10 + # Get any explicit position of an event.
3.11 +
3.12 + if event_details.has_key("geo"):
3.13 + latitude, longitude = event_details["geo"]
3.14 +
3.15 + # Or look up the position of a location using the locations
3.16 + # page.
3.17 +
3.18 + else:
3.19 + latitude, longitude = getLocationPosition(location, locations)
3.20
3.21 # Use a normalised location if necessary.
3.22
3.23 @@ -1598,6 +1605,8 @@
3.24
3.25 event_locations[location] = latitude, longitude
3.26
3.27 + # Record events according to location.
3.28 +
3.29 if not events_by_location.has_key(location):
3.30 events_by_location[location] = []
3.31