<commit_before># -*- coding: utf-8 -*-
import string
import posixpath
import random
import calendar
import datetime
import textwrap
import cgi

from py31compat.functools import lru_cache

import cherrypy
import pkg_resources
import jinja2.loaders
import pytz
from jaraco.util.numbers import ordinalth as th_it

import pmxbot.core
import pmxbot.logging
import pmxbot.util

jenv = jinja2.Environment(loader=jinja2.loaders.PackageLoader('pmxbot.web'))
TIMEOUT=10.0


colors = ["06F", "900", "093", "F0C", "C30", "0C9", "666", "C90", "C36",
	"F60", "639", "630", "966", "69C", "039", '7e1e9c', '15b01a', '0343df',
	'ff81c0', '653700', 'e50000', '029386', 'f97306', 'c20078', '75bbfd']
random.shuffle(colors)

def get_context():
	c = cherrypy.request.app.config['botconf']['config']
	d = dict(
		request = cherrypy.request,
		name = c.bot_nickname,
		config = c,
		base = c.web_base,
		logo = c.logo
	)
	return d

def make_anchor(line):
	time, nick = line
	return "%s.%s" % (str(time).replace(':', '.'), nick)

def pmon(month):
	"""
	P the month

	>>> pmon('2012-08')
	'August, 2012'
	"""
	year, month = month.split('-')
	return '{month_name}, {year}'.format(
		month_name = calendar.month_name[int(month)],
		year = year,
	)

def pday(dayfmt):
	"""
	P the day

	>>> pday('2012-08-24')
	'Friday the 24th'
	"""

	year, month, day = map(int, dayfmt.split('-'))
	return '{day} the {number}'.format(
		day = calendar.day_name[calendar.weekday(year, month, day)],
		number = th_it(day),
	)

rev_month = {}
for x in xrange(1, 13):
	rev_month[calendar.month_name[x]] = x

def sort_month_key(m):
	parts = m.split(',')
	parts[0] = rev_month[parts[0]]
	return parts[1], parts[0]

def log_db():
	return pmxbot.logging.Logger.from_URI(
		cherrypy.request.app.config['botconf']['config'].database)

class ChannelPage(object):
	@cherrypy.expose
	def default(self, channel):
		page = jenv.get_template('channel.html')

		db = log_db()
		context = get_context()
		contents = db.get_channel_days(channel)
		months = {}
		for fn in sorted(contents, reverse=True):
			mon_des, day = fn.rsplit('-', 1)
			months.setdefault(pmon(mon_des), []).append((pday(fn), fn))
		sort_key = lambda v: sort_month_key(v[0])
		context['months'] = sorted(months.items(), key=sort_key, reverse=True)
		context['channel'] = channel
		return page.render(**context).encode('utf-8')

class DayPage(object):<commit_msg>Clean up rev_month<commit_after># -*- coding: utf-8 -*-
import string
import posixpath
import random
import calendar
import datetime
import textwrap
import cgi

from py31compat.functools import lru_cache

import cherrypy
import pkg_resources
import jinja2.loaders
import pytz
from jaraco.util.numbers import ordinalth as th_it

import pmxbot.core
import pmxbot.logging
import pmxbot.util

jenv = jinja2.Environment(loader=jinja2.loaders.PackageLoader('pmxbot.web'))
TIMEOUT=10.0


colors = ["06F", "900", "093", "F0C", "C30", "0C9", "666", "C90", "C36",
	"F60", "639", "630", "966", "69C", "039", '7e1e9c', '15b01a', '0343df',
	'ff81c0', '653700', 'e50000', '029386', 'f97306', 'c20078', '75bbfd']
random.shuffle(colors)

def get_context():
	c = cherrypy.request.app.config['botconf']['config']
	d = dict(
		request = cherrypy.request,
		name = c.bot_nickname,
		config = c,
		base = c.web_base,
		logo = c.logo
	)
	return d

def make_anchor(line):
	time, nick = line
	return "%s.%s" % (str(time).replace(':', '.'), nick)

def pmon(month):
	"""
	P the month

	>>> pmon('2012-08')
	'August, 2012'
	"""
	year, month = month.split('-')
	return '{month_name}, {year}'.format(
		month_name = calendar.month_name[int(month)],
		year = year,
	)

def pday(dayfmt):
	"""
	P the day

	>>> pday('2012-08-24')
	'Friday the 24th'
	"""

	year, month, day = map(int, dayfmt.split('-'))
	return '{day} the {number}'.format(
		day = calendar.day_name[calendar.weekday(year, month, day)],
		number = th_it(day),
	)

rev_month = dict(
	(calendar.month_name[m_ord], m_ord)
	for m_ord in xrange(1, 13)
)

def sort_month_key(m):
	parts = m.split(',')
	parts[0] = rev_month[parts[0]]
	return parts[1], parts[0]

def log_db():
	return pmxbot.logging.Logger.from_URI(
		cherrypy.request.app.config['botconf']['config'].database)

class ChannelPage(object):
	@cherrypy.expose
	def default(self, channel):
		page = jenv.get_template('channel.html')

		db = log_db()
		context = get_context()
		contents = db.get_channel_days(channel)
		months = {}
		for fn in sorted(contents, reverse=True):
			mon_des, day = fn.rsplit('-', 1)
			months.setdefault(pmon(mon_des), []).append((pday(fn), fn))
		sort_key = lambda v: sort_month_key(v[0])
		context['months'] = sorted(months.items(), key=sort_key, reverse=True)
		context['channel'] = channel
		return page.render(**context).encode('utf-8')

class DayPage(object):
{'fraction_non_alphanumeric': 0.1785864535128313, 'fraction_numerical': 0.04964240639461506, 'mean_word_length': 4.87037037037037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1638236', 'n_tokens_mistral': 2062, 'n_tokens_neox': 1847, 'n_words': 408}