def main(): start_time = time.time() if len(sys.argv) != 2: print_usage() exit() command = sys.argv[1] main_data = load_or_die('site', 'main.yaml') main_data['current_show_page'] = main_data['Current Show'] + '/show.html' current_year, current_season = main_data['Current Show'].split('/') shows.current_year = current_year shows.current_season = current_season data = {'main': main_data, 'current': load_or_die('site', current_year, current_season, 'show.yaml'), 'venues': load_or_die('site', 'venues.yaml'), 'tickets': load_or_die('site', 'tickets.yaml')} template_data = TemplateData(data, root + '/site', []) if command == 'all': make_all(template_data) elif command == 'shows': make_shows(template_data) elif command == 'about': render_about(template_data) else: print_usage() exit() print('Success!') print('Completed in %s seconds' % (time.time() - start_time))
def render_index(template_data): index_template = load_or_die('templates', 'index.htmpl') year, season = template_data.data['main']['Current Show'].split('/') graphic = shows.get_show_graphic(year, season) current_show_data = load_or_die('site', year, season, 'show.yaml') current_show_data.update({'year': year, 'season': season, 'graphic': graphic}) index_data = deepcopy(template_data) index_data.bind('show', current_show_data) rendered = evaluate_template(index_template, index_data) write(index_data, 'MIT Musical Theatre Guild', rendered, 'site', 'index.html')
def render_show_page(main_data, year, season): """ Renders the show page for a given slot, if it exists :param main_data: the main TemplateData instance :param year: the year to target :param season: the season to target :return: empty """ yaml_path = path.join(utils.root, 'site', year, season, 'show.yaml') if not path.isfile(yaml_path): return show_data = load_or_die(yaml_path) show_data.update({ 'year': year, 'season': season, 'graphic': get_show_graphic(year, season), 'is_current': year == current_year and season == current_season }) show_template_data = deepcopy(main_data) show_template_data.bind('show', show_data) show_template_data.path = [year, season] rendered = compiled_show_template.evaluate(show_template_data) write(show_template_data, 'MTG - ' + show_data['Title'] + ' (' + year + ")", rendered, 'site', year, season, 'show.html')
def make_show_list(main_data): """ Renders the show list page :param main_data: the main TemplateData instance :return: empty """ show_template_data = deepcopy(main_data) show_summaries = [] for year in get_defined_years(): for season in reversed(seasons): yaml_path = path.join(utils.root, 'site', year, season, 'show.yaml') if not path.isfile(yaml_path): continue show_data = load_or_die(yaml_path) graphic = get_show_graphic(year, season) is_current = year == current_year and season == current_season show_data.update({ 'year': year, 'season': season, 'graphic': graphic, 'is_current': is_current }) show_template_data.bind('show', show_data) show_summaries.append( compiled_summary_template.evaluate(show_template_data)) show_list_data = deepcopy(main_data) show_list_data.bind('show_list', show_summaries) write(show_list_data, 'MTG - Show List', compiled_show_list_template.evaluate(show_list_data), 'site', 'show_list.html')
def render_directions(template_data): directions_template = load_or_die('templates', 'directions.htmpl') rendered = evaluate_template(directions_template, template_data) write(template_data, 'MTG - Directions', rendered, 'site', 'directions.html')
def render_about(template_data): about_template = load_or_die('templates', 'about.htmpl') rendered = evaluate_template(about_template, template_data) write(template_data, 'MTG - About MTG', rendered, 'site', 'about.html')
def render_contact(template_data): contact_template = load_or_die('templates', 'contact.htmpl') rendered = evaluate_template(contact_template, template_data) write(template_data, 'MTG - Contact Us', rendered, 'site', 'contact.html')
def render_faq(template_data): faq_template = load_or_die('templates', 'faq.htmpl') rendered = evaluate_template(faq_template, template_data) write(template_data, 'MTG - Frequently Asked Questions', rendered, 'site', 'faq.html')
import re from copy import deepcopy from os import listdir, path import utils from htmpl import compile_template from utils import load_or_die, write compiled_show_template = compile_template( load_or_die('templates', 'show.htmpl')) compiled_summary_template = compile_template( load_or_die('templates', 'summary.htmpl')) compiled_show_list_template = compile_template( load_or_die('templates', 'show_list.htmpl')) seasons = ['IAP', 'Spring', 'Summer', 'Fall'] current_year = 0 current_season = '' def render_show_page(main_data, year, season): """ Renders the show page for a given slot, if it exists :param main_data: the main TemplateData instance :param year: the year to target :param season: the season to target :return: empty """ yaml_path = path.join(utils.root, 'site', year, season, 'show.yaml') if not path.isfile(yaml_path):