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

import argparse
import json
import math

parser = argparse.ArgumentParser()
parser.add_argument("--text", required=True, help="Input text")
parser.add_argument("--short", action='store_true')
args = parser.parse_args()

VALID_CHARS = u'qwertzuiopasdfghjklyxcvbnm1234567890QWERTZUIOPASDFGHJKLYXCVBNM ?:.,;-=/+ěščřžýáíéĚŠČŘŽÝÁÍÉůúŇ'

def chars_score(text):
    known_cnt = 0
    for char in text:
        if char in VALID_CHARS:
            known_cnt += 1
    return float(known_cnt)/len(text)

def length_score(text):
    cnt = 0
    for char in text:
        if char in VALID_CHARS:
            cnt += 1
    return min(math.log(cnt, 1000), 1.0)

# TODO: add another functions here
# def xyz_score(text):
#    text magic here
#    return 0.5


def compute(scores):
    total = 0
    cnt = 0
    for score in scores:
        cnt += 1
        total = (total * (cnt-1) + score['value']) / cnt;
    return {'score': total, 'parts': scores}


scores = []
scores.append({'name': 'chars_score', 'value': chars_score(args.text)})
scores.append({'name': 'length_score', 'value': length_score(args.text)})
# TODO: add another functions here
# scores.append({'name': 'xyz_score', 'value': xyz_score(args.text)})

total_score = compute(scores)

if args.short:
    print(total_score['score'])
else:
    print(json.dumps(total_score, sort_keys=True, indent=4))

@@ -40,16 +40,56 @@
 -8 -*-%0A%0A
+from __future__ import unicode_literals%0A
 import a
@@ -300,16 +300,55 @@
 args()%0A%0A
+input_text = args.text.decode('utf8')%0A%0A
 VALID_CH
@@ -861,17 +861,16 @@
 rn 0.5%0A%0A
-%0A
 def comp
@@ -1054,17 +1054,16 @@
 cores%7D%0A%0A
-%0A
 scores =
@@ -1121,29 +1121,30 @@
 chars_score(
-args.
+input_
 text)%7D)%0Ascor
@@ -1196,29 +1196,30 @@
 ength_score(
-args.
+input_
 text)%7D)%0A# TO

fix utf8 text input by decode()