فهرست منبع

ics con accenti (solo py3)

boyska 6 سال پیش
والد
کامیت
5a6e68909a
1فایلهای تغییر یافته به همراه10 افزوده شده و 3 حذف شده
  1. 10 3
      plugins/talks.py

+ 10 - 3
plugins/talks.py

@@ -180,7 +180,8 @@ def get_talk_data(talkname):
 
 def overlap(interval_a, interval_b):
     '''how many minutes do they overlap?'''
-    return max(0, min(interval_a[1], interval_b[1]) - max(interval_a[0], interval_b[0]))
+    return max(0, min(interval_a[1], interval_b[1]) -
+               max(interval_a[0], interval_b[0]))
 
 
 def get_talk_overlaps(name):
@@ -376,12 +377,18 @@ def talks_to_ics():
 
 
 def talk_to_ics(talk):
+    def _decode(s):
+        if six.PY2:
+            return unidecode.unidecode(s)
+        else:
+            return s
+
     if 'time' not in talk or 'duration' not in talk:
         return None
     e = ics.Event(
         uid="%s@%d.hackmeeting.org" % (talk['id'],
                                        get_global_data()['startdate'].year),
-        name=unidecode.unidecode(talk['title']),
+        name=_decode(talk['title']),
         begin=talk['time'],
         duration=datetime.timedelta(minutes=talk['duration']),
         transparent=True,
@@ -390,7 +397,7 @@ def talk_to_ics(talk):
     # unidecode replaces letters with their most similar ASCII counterparts
     # (ie: accents get stripped)
     if 'text' in talk:
-        e.description = unidecode.unidecode(talk['text'])
+        e.description = _decode(talk['text'])
     e.url = pelican.settings['SCHEDULEURL'] + '#talk-' + talk['id']
     if 'room' in talk:
         e.location = talk['room']