<commit_before>#!/usr/bin/env python

import codecs
import json
from os import path
import shutil

from layers.external_citation import ExternalCitationLayer
from layers.internal_citation import InternalCitationLayer
from layers.definitions import DefinitionsLayer
from layers.interpretations import InterpretationsLayer
from layers.layers_applier import LayersApplier
from layers.toc_applier import TableOfContentsLayer
from html_builder import HTMLBuilder
import api_reader

import settings as app_settings
from django.conf import settings


def write_file(filename, markup):
    """ Write out a file using the UTF-8 codec. """
    f = codecs.open(filename, 'w', encoding='utf-8')
    f.write(markup)
    f.close()

if __name__ == "__main__":
    if not settings.configured:
        settings.configure(TEMPLATE_DEBUG=False, 
            TEMPLATE_LOADERS=('django.template.loaders.filesystem.Loader',), 
            TEMPLATE_DIRS = ('templates/',))

    api = api_reader.Client(app_settings.API_BASE)
    regulation, version = "1005", "20111227"
    reg_json = api.regulation(regulation, version)

    layers_applier = LayersApplier()

    el = api.layer("external-citations", regulation, version)
    reference_EFT_act = ['15', '1693'] #Title 15, Section 1693 of the United States Code

    layers_applier.add_layer(ExternalCitationLayer(el, ['15', '1693']))
    il = api.layer("internal-citations", regulation, version)
    layers_applier.add_layer(InternalCitationLayer(il))

    dl = api.layer("terms", regulation, version)
    layers_applier.add_layer(DefinitionsLayer(dl))

    intl = api.layer("interpretations", regulation, version)
    layers_applier.add_layer(InterpretationsLayer(intl))
    
    tl = api.layer("toc", regulation, version)
    toc_applier = TableOfContentsLayer(tl)

    makers_markup = HTMLBuilder(layers_applier, toc_applier)
    makers_markup.tree = reg_json
    makers_markup.generate_html()
    markup = makers_markup.render_markup()

    write_file('/tmp/rege.html', markup)
    front_end_dir = '/tmp/front_end'
    if not path.islink(front_end_dir):
        shutil.rmtree(front_end_dir)
        shutil.copytree('../front_end', front_end_dir)<commit_msg>whoops, adding back path.exists() check<commit_after>#!/usr/bin/env python

import codecs
import json
from os import path
import shutil

from layers.external_citation import ExternalCitationLayer
from layers.internal_citation import InternalCitationLayer
from layers.definitions import DefinitionsLayer
from layers.interpretations import InterpretationsLayer
from layers.layers_applier import LayersApplier
from layers.toc_applier import TableOfContentsLayer
from html_builder import HTMLBuilder
import api_reader

import settings as app_settings
from django.conf import settings


def write_file(filename, markup):
    """ Write out a file using the UTF-8 codec. """
    f = codecs.open(filename, 'w', encoding='utf-8')
    f.write(markup)
    f.close()

if __name__ == "__main__":
    if not settings.configured:
        settings.configure(TEMPLATE_DEBUG=False, 
            TEMPLATE_LOADERS=('django.template.loaders.filesystem.Loader',), 
            TEMPLATE_DIRS = ('templates/',))

    api = api_reader.Client(app_settings.API_BASE)
    regulation, version = "1005", "20111227"
    reg_json = api.regulation(regulation, version)

    layers_applier = LayersApplier()

    el = api.layer("external-citations", regulation, version)
    reference_EFT_act = ['15', '1693'] #Title 15, Section 1693 of the United States Code

    layers_applier.add_layer(ExternalCitationLayer(el, ['15', '1693']))
    il = api.layer("internal-citations", regulation, version)
    layers_applier.add_layer(InternalCitationLayer(il))

    dl = api.layer("terms", regulation, version)
    layers_applier.add_layer(DefinitionsLayer(dl))

    intl = api.layer("interpretations", regulation, version)
    layers_applier.add_layer(InterpretationsLayer(intl))
    
    tl = api.layer("toc", regulation, version)
    toc_applier = TableOfContentsLayer(tl)

    makers_markup = HTMLBuilder(layers_applier, toc_applier)
    makers_markup.tree = reg_json
    makers_markup.generate_html()
    markup = makers_markup.render_markup()

    write_file('/tmp/rege.html', markup)
    front_end_dir = '/tmp/front_end'
    if not path.islink(front_end_dir):
        if path.exists(front_end_dir):
            shutil.rmtree(front_end_dir)
        shutil.copytree('../front_end', front_end_dir)
{'fraction_non_alphanumeric': 0.10078740157480315, 'fraction_numerical': 0.014398200224971878, 'mean_word_length': 4.5092936802973975, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2394764', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1331, 'n_words': 297}