Beispiel #1
0
def generate_talk_page(talk_index, conferences, output_directory, index_page,
                       debug_mode):
    talktitle = talk_index
    filetitle = generate_filename(talktitle)
    outputfilename = filetitle + '.html'
    filepath = output_directory + filetitle + '.html'

    print("creating file: {0}".format(filetitle))

    pagevalues = copy.deepcopy(pagevariables)
    pagevalues['title'] = format_talk_page_title.format(talktitle)
    pagevalues['talktitle'] = talktitle
    pagevalues['filename'] = outputfilename
    recordings = []
    slides = []
    presentations = []
    reactions = []
    description = ''

    if os.path.isfile('public/talks/' + filetitle + '.jpg'):
        photofile = filetitle + '.jpg'
        photo = format_photo_div.format(photofile)
        pagevalues['photo'] = photo

    for conference in conferences:
        this_talk = None
        for talk in conference['talks']:
            if (talk_index
                    == talk['talk']) or (('root-talk' in talk) and
                                         (talk['root-talk'] == talk_index)):
                this_talk = talk

        if (this_talk is not None):
            this_talk[u'outputfilename'] = outputfilename
            talk_date = common.get_talk_date(this_talk)

            if ('talk-description' in this_talk) and (len(
                    this_talk['talk-description']) > len(description)):
                #pick the longest description (figuring it is the most imformative)
                description = this_talk['talk-description']

            conference_name = conference['conference']
            if 'recording-url' in this_talk:
                recordings.append({
                    'date': talk_date,
                    'recording-url': this_talk['recording-url'],
                    'conference': conference_name
                })

            if ('slides-url' in this_talk) and (not any(
                    d.get('slides-url', None) == this_talk['slides-url']
                    for d in slides)):
                slides.append({
                    'date': talk_date,
                    'slides-url': this_talk['slides-url'],
                    'talk': this_talk['talk']
                })

            conference_location = common.format_city_state_country_from_location(
                this_talk['location']
            ) if 'location' in this_talk else "virtual"

            talk_list_item_format = format_presentation_list_item
            if this_talk['talk-type'] == talk_type_keynote:
                talk_list_item_format = format_keynote_list_item

            presentations.append(
                talk_list_item_format.format(conference_name,
                                             talk_date.strftime("%B %d, %Y"),
                                             conference_location))

            if 'reactions' in this_talk:
                for reaction in this_talk['reactions']:
                    quote = reaction['quote']
                    credit = reaction['credit']
                    if 'reference-url' in reaction:
                        reactions.append(
                            format_reactions_list_item.format(
                                quote, reaction['reference-url'], credit))
                    else:
                        reactions.append(
                            format_reactions_list_item_no_link.format(
                                quote, credit))
            try:
                index = next(index
                             for (index, d) in enumerate(index_page['talks'])
                             if d["name"] == talk_index)
                if talk_date > index_page['talks'][index]['date']:
                    index_page['talks'][index]['date'] = talk_date
            except StopIteration:
                index_page['talks'].append({
                    'name': talk_index,
                    'file': outputfilename,
                    'date': talk_date
                })

    if len(description) > 0:
        pagevalues['description'] = description

    if len(recordings) > 0:
        # get the embed code for the first recording, since it is the most recent
        sorted_recordings = sorted(recordings,
                                   key=itemgetter('date'),
                                   reverse=True)
        other_recordings = []
        video_string = ''
        for recording in sorted_recordings:
            if len(video_string) == 0:
                embed_url = recording['recording-url']
                embed_code = get_embed_code_from_videoURL(embed_url)
                if len(embed_code) > 0:
                    video_string = format_video_div + embed_code
                else:
                    other_recordings.append(recording)
            else:
                other_recordings.append(recording)

        other_recordings_string = ''
        if len(other_recordings) > 0:
            if len(video_string) < 1:
                video_string = format_video_div
                other_recordings_string = format_other_recordings_list_no_embeddable
            else:
                other_recordings_string = format_other_recordings_list
            other_recordings_list = ''
            for recording in other_recordings:
                other_recordings_list += format_other_recordings_list_item.format(
                    recording['recording-url'], recording['conference'],
                    recording['date'].year)
            other_recordings_string = other_recordings_string.format(
                other_recordings_list)
            video_string += other_recordings_string
        video_string += format_close_div
        pagevalues['video'] = video_string

    if len(slides) > 0:
        sorted_slides = sorted(slides, key=itemgetter('date'), reverse=True)
        embed_url = sorted_slides[0]['slides-url']
        slides_string = format_slides_div + get_embed_code_from_slides_URL(
            embed_url)

        other_slides_string = ''
        if len(sorted_slides) > 1:
            other_slides_string = format_other_slides_list
            iterslides = iter(sorted_slides)
            next(iterslides)
            other_slides_list = ''
            for slide in iterslides:
                other_slides_list += format_other_slides_list_item.format(
                    slide['slides-url'], slide['talk'], slide['date'].year)
            other_slides_string = other_slides_string.format(other_slides_list)
            slides_string += other_slides_string
        slides_string += format_close_div
        pagevalues['slides'] = slides_string

    if len(presentations) > 0:
        pagevalues['presentationlist'] = '\n'.join(presentations)
    else:
        pagevalues['presentationlist'] = ''

    if len(reactions) > 0:
        reactionstring = format_reactions_div.format('\n'.join(reactions))
        pagevalues['reactions'] = reactionstring
    else:
        pagevalues['reactions'] = ''

    pagevalues['sitenav'] = generate_nav_talk(False, debug_mode)
    pagevalues['siteroot'] = get_href_root('index.html', debug_mode, True)
    pagevalues['talkroot'] = get_talk_root_for_talk(debug_mode)

    common.check_for_missing_values(pagevariables, pagevalues)

    with open(filepath, 'w') as f:
        f.write(talkpagetemplate.substitute(pagevalues))

    return index_page
    def test_get_href_root(self):
        """test get_href_root in module navigation"""
        self.assertEqual(navigation.get_href_root('index.html', True),
                         'index.html')
        self.assertEqual(navigation.get_href_root('../index.html', True),
                         '../index.html')
        self.assertEqual(navigation.get_href_root('index.html', False),
                         'https://kevingoldsmith.com/')
        self.assertEqual(navigation.get_href_root('index.html'),
                         'https://kevingoldsmith.com/')
        #this is bogus as a corner case, but it is the expected behavior, we should fail if it changes
        self.assertEqual(navigation.get_href_root('../index.html', False),
                         'https://kevingoldsmith.com/../')

        self.assertEqual(navigation.get_href_root('resume.html', True),
                         'resume.html')
        self.assertEqual(navigation.get_href_root('resume.html', False),
                         'https://kevingoldsmith.com/resume.html')

        self.assertEqual(navigation.get_href_root('talks/index.html', True),
                         'talks/index.html')
        self.assertEqual(navigation.get_href_root('talks/index.html', False),
                         'https://kevingoldsmith.com/talks/')

        self.assertEqual(navigation.get_href_root('index.html', True, True),
                         '../index.html')
        self.assertEqual(navigation.get_href_root('../index.html', True, True),
                         '../../index.html')
        self.assertEqual(navigation.get_href_root('index.html', False, True),
                         'https://kevingoldsmith.com/')
        #this is bogus as a corner case, but it is the expected behavior, we should fail if it changes
        self.assertEqual(
            navigation.get_href_root('../index.html', False, True),
            'https://kevingoldsmith.com/../')

        self.assertEqual(navigation.get_href_root('resume.html', True, True),
                         '../resume.html')
        self.assertEqual(navigation.get_href_root('resume.html', False, True),
                         'https://kevingoldsmith.com/resume.html')

        self.assertEqual(
            navigation.get_href_root('talks/index.html', True, True),
            '../talks/index.html')
        self.assertEqual(
            navigation.get_href_root('talks/index.html', False, True),
            'https://kevingoldsmith.com/talks/')
Beispiel #3
0
parser = argparse.ArgumentParser(description='generate the sitemap')
parser.add_argument('--debug', action='store_true')
args = parser.parse_args()
debug_mode = args.debug

sitemap_files = []
path = get_output_directory(debug_mode)
for (path, dirs, files) in os.walk(path):
    for file in files:
        ext = os.path.splitext(file)[1]
        if (not file in ignore_files) and (ext == '.html'):
            path_list = path.split(os.sep)
            #cheat since I know that there is only a single depth
            sitemap_files.append(
                (os.path.join(path, file),
                 get_href_root(os.path.join(path_list[1], file), debug_mode)))

sitemap_entries = []
for file in sitemap_files:
    sitemap_entries.append(
        format_url.format(url=file[1],
                          date=datetime.datetime.fromtimestamp(
                              os.path.getmtime(file[0])).strftime('%Y-%m-%d')))

with open('templates/sitemap-template.xml') as f:
    template = Template(f.read())

d = dict(urllist='\n'.join(sitemap_entries))
print('writing: sitemap.xml')
with open(get_output_directory(debug_mode) + 'sitemap.xml', 'w') as f:
    f.write(template.substitute(d))
#!/usr/bin/env python

import argparse
from string import Template
from navigation import generate_nav_root, get_href_root
from common import get_output_directory

parser = argparse.ArgumentParser(description='generate the writings file')
parser.add_argument('--debug', action='store_true')
args = parser.parse_args()
debug_mode = args.debug

other_pages = [('index.html', 'templates/site-index-template.html'),
               ('music.html', 'templates/music-template.html'),
               ('photography.html', 'templates/photography-template.html')]

for page in other_pages:
    with open(page[1]) as f:
        pagetemplate = Template(f.read())

    d = dict(sitenav=generate_nav_root(page[0], debug_mode),
             siteroot=get_href_root('index.html', debug_mode))
    print('writing: ' + page[0])
    with open(get_output_directory(debug_mode) + page[0], 'w') as f:
        f.write(pagetemplate.substitute(d))
                item = format_presentation_list_item.format(
                    conference_name, talk_date.strftime("%B %d, %Y"),
                    conference_location)

            if item not in future_talks_list_items:
                future_talks_list_items.append(item)

    future_talks_string = format_future_talks.format(
        '\n'.join(future_talks_list_items))

#get the page variables (which becomes our template dictionary)
with open('data/pagevariables.json') as f:
    pagevariables = json.load(f)

pagevalues = copy.deepcopy(pagevariables)
pagevalues['currenttalklist'] = featured_talks_string
pagevalues['othertalklist'] = other_talks_string
pagevalues['panellist'] = panel_list_string
pagevalues['workshoplist'] = lab_list_string
pagevalues['title'] = 'Talks: Kevin Goldsmith'
pagevalues['presentationlist'] = ''
pagevalues['description'] = 'Kevin Goldsmith Talks'
pagevalues['markerlist'] = ',\n'.join(marker_list)
pagevalues['infolist'] = ',\n'.join(info_list)
pagevalues['futuretalks'] = future_talks_string
pagevalues['sitenav'] = generate_nav_talk(True, debug_mode)
pagevalues['siteroot'] = get_href_root('index.html', debug_mode, True)
common.check_for_missing_values(pagevariables, pagevalues)
with open(output_directory + 'index.html', 'w') as f:
    f.write(talkpagetemplate.substitute(pagevalues))