Esempio n. 1
0
def render_HTML(data, tpl_name, output_path=None, courses=None, lang='sk', mode='regular'):
    """Render the course data into separate HTML files named by the course codes.

    Params:
        data: list of dicts
        output_path:
        courses: dict of all courses uses for creating cross-document links
    """
    # nacitanie HTML sablony
    script_abs_path = os.path.dirname(os.path.abspath(__file__))
    env = Environment(loader=FileSystemLoader(script_abs_path))
    html_tpl = env.get_template(tpl_name)

    # zapis do HTML suborov
    for course in data:
        kod_predmetu = course['kod']

        course['podmienujucePredmety'] = utils.replace_codes(course['podmienujucePredmety'], lang, add_links=True, courses=courses, and_symbol=trans[lang]['a'])
        course['vylucujucePredmety'] = utils.replace_codes(course['vylucujucePredmety'], lang, add_links=True, courses=courses)
        course['obsahovaPrerekvizita'] = utils.replace_codes(course['obsahovaPrerekvizita'], lang, add_links=True, courses=courses)

        html = html_tpl.render(course)

        filename = '%s.html' % kod_predmetu
        filename = filename.replace("/","_")
        if output_path is not None:
            path = os.path.join(output_path, filename)
            if not os.path.exists(output_path):
                os.mkdir(output_path)
        else:
            path = filename
        with open(path, 'w') as f:
            f.write(html.encode('utf8'))
Esempio n. 2
0
    def test_replace_codes(self):
        data = {
            'FMFI.KJP/1-MXX-151/00': '1-MXX-151_00',
            u'(FMFI.KMANM/1-MAT-150/00 alebo FMFI.KMANM/1-MMN-150/00 alebo FMFI.KAMŠ/1-EFM-130/00) , (FMFI.KAGDM/1-MAT-120/00 alebo FMFI.KAGDM/1-MMN-120/00)': u'(1-MAT-150_00 alebo 1-MMN-150_00 alebo 1-EFM-130_00) a (1-MAT-120_00 alebo 1-MMN-120_00)',
            None: '',
            '1-INF-210 Úvod do matematickej logiky a 1-AIN-411 Úvod do výpočtovej logiky': '1-INF-210 Úvod do matematickej logiky a 1-AIN-411 Úvod do výpočtovej logiky'
        }
        data_links = {
            u'(FMFI.KMANM/1-MAT-150/00 alebo FMFI.KMANM/1-MMN-150/00 alebo FMFI.KAMŠ/1-EFM-130/00) , (FMFI.KAGDM/1-MAT-120/00 alebo FMFI.KAGDM/1-MMN-120/00)': u'(<a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-MAT-150_00.html">1-MAT-150_00</a> alebo <a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-MMN-150_00.html">1-MMN-150_00</a> alebo <a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-EFM-130_00.html">1-EFM-130_00</a>) a (<a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-MAT-120_00.html">1-MAT-120_00</a> alebo <a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-MMN-120_00.html">1-MMN-120_00</a>)'
        }
        data_links_courses = {
            u'(FMFI.KMANM/1-MAT-150/00 alebo FMFI.KMANM/1-MMN-150/00 alebo FMFI.KAMŠ/1-EFM-130/00) , (FMFI.KAGDM/1-MAT-120/00 alebo FMFI.KAGDM/1-MMN-120/00)': u'(<a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-MAT-150_00.html">1-MAT-150_00 Matematická analýza (2)</a> alebo <a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-MMN-150_00.html">1-MMN-150_00 Matematická analýza (2)</a> alebo <a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-EFM-130_00.html">1-EFM-130_00 Matematická analýza (2)</a>) a (<a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-MAT-120_00.html">1-MAT-120_00 Lineárna algebra a geometria (1)</a> alebo <a href="https://sluzby.fmph.uniba.sk/infolist/SK/1-MMN-120_00.html">1-MMN-120_00 Lineárna algebra a geometria (1)</a>)'
        }
        courses = {
            '1-MMN-150_00': u'Matematická analýza (2)',
            '1-MAT-150_00': u'Matematická analýza (2)',
            '1-EFM-130_00': u'Matematická analýza (2)',
            '1-MAT-120_00': u'Lineárna algebra a geometria (1)',
            '1-MMN-120_00': u'Lineárna algebra a geometria (1)'
        }

        for in_data, out_data in data.iteritems():
            self.assertEqual(utils.replace_codes(in_data, and_symbol='a'), out_data)

        for in_data, out_data in data_links.iteritems():
            self.assertEqual(utils.replace_codes(in_data, add_links=True, and_symbol='a'), out_data)

        for in_data, out_data in data_links_courses.iteritems():
            self.assertEqual(utils.replace_codes(in_data, courses=courses, add_links=True, and_symbol='a'), out_data)
 # coding=utf8
import utils

print utils.parse_code(u"FMFI.KAMŠ+KAI/1-EFM-380/00");
print utils.parse_code(u"PriF.KBCh/N-bCBI-303/10");
print utils.parse_code(u"PriF.KBCh/N-bCBI-303/3ecf/10");
print utils.parse_code(u"alebo");

print utils.replace_codes(u"FMFI.KAMŠ/1-MAT-282/00 alebo FMFI.KAMŠ/2-INF-175/15", add_links=True);
print utils.replace_codes(u"FMFI.KI+KAI/2-INF-262/15 - Bezpečnosť IT infraštruktúry  a FMFI.KI/2-INF-178/15 - Kryptológia (1)  a FMFI.KI/2-INF-223/15 - Riadenie IT bezpečnosti  a FMFI.KI/2-INF-183/15 - Počítačové siete (2)  a FMFI.KI/2-INF-176/15 - UNIX pre administrátorov  a FMFI.KI/2-INF-224/15 - Teória informácie a teória kódovania (1)  a FMFI.KI/2-INF-225/15 - Teória informácie a teória kódovania (2)");