<commit_before>import os
import time
import copy
from collections import OrderedDict
import shutil
import re
import json
from http.server import HTTPServer, CGIHTTPRequestHandler 
from jinja2 import Environment, FileSystemLoader, select_autoescape
from livereload import Server
import logging
import logging.config

env = None
global_config = None

VERSION = "0.1.0"

PLUGINS_PATH = 'plugins'

LOGGING = {
    'version': 1,
    #'formatters':{
    #    'default': {
    #        'format': '%(asctime)s %(levelname)s %(name)s %(message)s'
    #    },
    #},
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
        'file':{
            'class': 'logging.FileHandler',
            #'formatter': 'default',
            'filename': 'site.log',
            'mode': 'w',
            #'encoding': 'utf-8',
        },
    },
    'root': {
        'handlers': ['console','file'],
        'level' : 'DEBUG',
    },
}

logging.config.dictConfig(LOGGING)
#logger = logging.getLogger("mylogger")

def loadjson(fn):
    f = open(fn)
    c = json.loads(f.read(),object_pairs_hook=OrderedDict)
    f.close()
    return c

def config():
    global env
    c = loadjson('config.json')

    env = Environment(
        loader=FileSystemLoader([os.path.join(os.getcwd(),'theme',c['theme']),os.path.join(os.getcwd(),PLUGINS_PATH)]),
        autoescape=select_autoescape(['html', 'xml'])
    )
    return c

def render(tpl,context):
    t = env.get_template(tpl) 
    return t.render(context)

def get_md_content(md_path):
    print("md_file=%s"%md_path)
    f = open(md_path)
    s = f.read()
    p = r'\{[^}]*\}'
    m = re.search(p,s)
    if m:
        head = m.group(0)
        head_dict = json.loads(head)
        date = head_dict['date']
        content = s.replace(head,'')
        if global_config['add_data']:
            content += "\n %s"%date
        title = head_dict['title']
    else:
        date = time.ctime(os.stat(md_path).st_ctime)
        m = re.search(r'#(.+)',s)
        if m:
            titile = re.search(r'#(.+)',s).group(1)
        else:
            title = ""
        if global_config['add_data']:
            content = s + "\n %s"%date
        else:
            content = s
    f.close()
    return content,title,date

<commit_msg>fix typo<commit_after>import os
import time
import copy
from collections import OrderedDict
import shutil
import re
import json
from http.server import HTTPServer, CGIHTTPRequestHandler 
from jinja2 import Environment, FileSystemLoader, select_autoescape
from livereload import Server
import logging
import logging.config

env = None
global_config = None

VERSION = "0.1.0"

PLUGINS_PATH = 'plugins'

LOGGING = {
    'version': 1,
    #'formatters':{
    #    'default': {
    #        'format': '%(asctime)s %(levelname)s %(name)s %(message)s'
    #    },
    #},
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
        'file':{
            'class': 'logging.FileHandler',
            #'formatter': 'default',
            'filename': 'site.log',
            'mode': 'w',
            #'encoding': 'utf-8',
        },
    },
    'root': {
        'handlers': ['console','file'],
        'level' : 'DEBUG',
    },
}

logging.config.dictConfig(LOGGING)
#logger = logging.getLogger("mylogger")

def loadjson(fn):
    f = open(fn)
    c = json.loads(f.read(),object_pairs_hook=OrderedDict)
    f.close()
    return c

def config():
    global env
    c = loadjson('config.json')

    env = Environment(
        loader=FileSystemLoader([os.path.join(os.getcwd(),'theme',c['theme']),os.path.join(os.getcwd(),PLUGINS_PATH)]),
        autoescape=select_autoescape(['html', 'xml'])
    )
    return c

def render(tpl,context):
    t = env.get_template(tpl) 
    return t.render(context)

def get_md_content(md_path):
    print("md_file=%s"%md_path)
    f = open(md_path)
    s = f.read()
    p = r'\{[^}]*\}'
    m = re.search(p,s)
    if m:
        head = m.group(0)
        head_dict = json.loads(head)
        date = head_dict['date']
        content = s.replace(head,'')
        if global_config['add_date']:
            content += "\n %s"%date
        title = head_dict['title']
    else:
        date = time.ctime(os.stat(md_path).st_ctime)
        m = re.search(r'#(.+)',s)
        if m:
            title = re.search(r'#(.+)',s).group(1)
        else:
            title = ""
        if global_config['add_date']:
            content = s + "\n %s"%date
        else:
            content = s
    f.close()
    return content,title,date


{'fraction_non_alphanumeric': 0.16024518388791595, 'fraction_numerical': 0.0035026269702276708, 'mean_word_length': 2.354625550660793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3539675', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1578, 'n_words': 311}