<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import yaml

from os import path as p
from pprint import pprint
from io import open
from flask import current_app as app
from flask.ext.script import Manager
from app import create_app

manager = Manager(create_app)
manager.add_option(
	'-m', '--cfgmode', dest='config_mode', default='Development')
manager.add_option('-f', '--cfgfile', dest='config_file', type=p.abspath)


def make_safe(name):
	return name.replace(' ', '_').replace('&', 'and').replace('/', '-')

def render_app(app, style):
	"""Renders the markup"""
	with app.test_client() as c:
		response = c.get('/render/%s/' % style)
		encoding = response.charset
		return response.data.decode(encoding)


@manager.option('-s', '--style', help='the proposal style, defaults to professional.md')
def propose(style=None):
	"""Create Proposal"""
	style = (style or app.config['STYLE'])
	stream = file(app.config['INFO_PATH'], 'r')
	details = yaml.safe_load(stream)
	client_name = details['client_name']
	safe_name = make_safe(client_name)
	html_file = p.join(app.config['EXPORT_DIR'], '%s_proposal.html' % safe_name)
	content = render_app(app, style)

	with open(html_file, 'w', encoding='utf-8') as f:
		f.write(content)


if __name__ == '__main__':
	manager.run()
<commit_msg>Make info file configurable<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import yaml

from os import path as p
from pprint import pprint
from io import open
from flask import current_app as app
from flask.ext.script import Manager
from app import create_app

manager = Manager(create_app)
manager.add_option(
	'-m', '--cfgmode', dest='config_mode', default='Development')
manager.add_option('-f', '--cfgfile', dest='config_file', type=p.abspath)


def make_safe(name):
	return name.replace(' ', '_').replace('&', 'and').replace('/', '-')

def render_app(app, style):
	"""Renders the markup"""
	with app.test_client() as c:
		response = c.get('/render/%s/' % style)
		encoding = response.charset
		return response.data.decode(encoding)


@manager.option('-i', '--info', help='the client info file, defaults to info.yml')
@manager.option('-s', '--style', help='the proposal style, defaults to professional.md')
def propose(info=None, style=None):
	"""Create Proposal"""
	style = (style or app.config['STYLE'])
	app.config['INFO_PATH'] = (info or app.config['INFO_PATH'])
	stream = file(app.config['INFO_PATH'], 'r')
	details = yaml.safe_load(stream)
	client_name = details['client_name']
	safe_name = make_safe(client_name)
	html_file = p.join(app.config['EXPORT_DIR'], '%s_proposal.html' % safe_name)
	content = render_app(app, style)

	with open(html_file, 'w', encoding='utf-8') as f:
		f.write(content)


if __name__ == '__main__':
	manager.run()

{'fraction_non_alphanumeric': 0.1714389271475172, 'fraction_numerical': 0.0014498006524102935, 'mean_word_length': 5.230248306997742, 'pattern_counts': {'":': 0, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6378484', 'n_tokens_mistral': 972, 'n_tokens_neox': 928, 'n_words': 239}