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

"""TODO:
 * more flexible sorting options
 * use -o to specify output file
 * check more explicitly for errors in JSON files
"""

import json, sys

if len(sys.argv) > 1:
    inFn = sys.argv[1]

with open(inFn, 'r') as f:
    try:
        defs = json.load(f)
    except:
        sys.exit('{} has a syntax error'.format(inFn))

sort = sorted(defs, key=str.lower)

print('# My Dictionary')
print('\n## Definitions')
curLetter = None
for k in sort:
    l = k[0].upper()
    if curLetter != l:
        curLetter = l
        print('\n### {}'.format(curLetter))
    word = k[0].upper() + k[1:]
    print('* *{}* - {}'.format(word, defs[k]))
<commit_msg>Print more explicit error reports for input file parsing<commit_after>#!/usr/bin/env python3

"""TODO:
 * more flexible sorting options
 * use -o to specify output file
"""

import json, sys

if len(sys.argv) > 1:
    inFn = sys.argv[1]

with open(inFn, 'r') as f:
    try:
        defs = json.load(f)
    except ValueError as e:
        sys.exit('ValueError in {}: {}'.format(inFn, e))

sort = sorted(defs, key=str.lower)

print('# My Dictionary')
print('\n## Definitions')
curLetter = None
for k in sort:
    l = k[0].upper()
    if curLetter != l:
        curLetter = l
        print('\n### {}'.format(curLetter))
    word = k[0].upper() + k[1:]
    print('* *{}* - {}'.format(word, defs[k]))

{'fraction_non_alphanumeric': 0.1788559015206372, 'fraction_numerical': 0.008689355539464157, 'mean_word_length': 2.9485714285714284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1573432', 'n_tokens_mistral': 508, 'n_tokens_neox': 495, 'n_words': 146}