From 8a818223805e74f64772e06926e3ae87be141e80 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 13 Feb 2016 13:40:23 -0500 Subject: LPSpeakersMarkdown writes speakers.ids to disk. The `speaker.ids` file contains a mapping of the speakers and their corresponding ids. This file will later be used by LPSMarkdown and LPSRenderer to auto link speakers while generating the sessions page. Addresses issue #7 --- lps_gen.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'lps_gen.py') diff --git a/lps_gen.py b/lps_gen.py index a153b95..3e74498 100644 --- a/lps_gen.py +++ b/lps_gen.py @@ -183,29 +183,29 @@ class LPSpeakersRenderer(Renderer): # 'keynote-speakers' or 'speakers'.' self.speaker_type = None - # Maintain a list of used IDs - self.used_ids = [] + # Maintain a dict of speakers and their IDs. + self.speakers_ids = OrderedDict() def mk_uid(self, text): """Returns a unique id. """ # 'John HÖcker, Onion Project' -> 'John HÖcker' - text = text.split(', ')[0] + speaker = unicode(text.split(', ')[0]) # 'John HÖcker' -> 'John Hacker' - ascii_text = unidecode(unicode(text)) + ascii_speaker = unidecode(speaker) # 'John Hacker' -> 'hacker' - id_ = ascii_text.split()[-1].lower() + id_ = ascii_speaker.split()[-1].lower() - if id_ not in self.used_ids: - self.used_ids.append(id_) + if id_ not in self.speakers_ids.values(): + self.speakers_ids[speaker]= id_ return id_ else: # 'John Hacker' -> 'john_hacker' - id_ = '_'.join([s.lower() for s in ascii_text.split()]) - self.used_ids.append(id_) + id_ = '_'.join([s.lower() for s in ascii_speaker.split()]) + self.speakers_ids[speaker] = id_ return id_ @@ -284,15 +284,21 @@ class LPSpeakersMarkdown(Markdown): """ Initialize with LPSpeakersRenderer as the renderer. """ - super(LPSpeakersMarkdown, self).__init__(renderer=LPSpeakersRenderer(), - inline=None, block=None, - **kwargs) + self.speakers_renderer = LPSpeakersRenderer() + super(LPSpeakersMarkdown, self).__init__( + renderer=self.speakers_renderer, + inline=None, block=None, + **kwargs) def parse(self, text): global lpspeakers_dict html = super(LPSpeakersMarkdown, self).parse(text) + + # Write mapping of speakers and their ids to speakers.ids. + json_write('speakers.ids', self.speakers_renderer.speakers_ids) + return lpspeakers_dict -- cgit v1.2.3