<commit_before>import sys
import json
import hashlib
import base64
import datetime
import os

from hippod import app


def load_data(path):
    with open(path) as data_file:
        return json.load(data_file)


def filter_data(data, user_filter):
    if type(data) != list:
        # empty list
        return ret

    ret = list()
    for item in data:
        skip_entry = False
        if user_filter:
            for key, value in user_filter.items():
                if key not in item:
                    skip_entry = True
                    break
                if key in item and item[key] != value:
                    skip_entry = True
                    break
        if skip_entry:
            continue

        entry = dict()
        # probably sensitive data, we opt-in here explicetly
        for i in ('username', 'color', 'email', 'fullname'):
            if i in item:
                entry[i] = item[i]
        ret.append(entry)
    return ret



def get(user_filter=None):
    path = app.config['CONF_USER_FILEPATH']
    data = load_data(path)
    return filter_data(data, user_filter)
<commit_msg>return proper (404) http status code for non-exist entry<commit_after>import sys
import json
import hashlib
import base64
import datetime
import os

from hippod import app


def load_data(path):
    with open(path) as data_file:
        return json.load(data_file)


def filter_data(data, user_filter):
    if type(data) != list:
        msg = "user DB contains no data - failed to search for record"
        raise ApiError(msg, http_code=404)

    ret = list()
    for item in data:
        skip_entry = False
        if user_filter:
            for key, value in user_filter.items():
                if key not in item:
                    skip_entry = True
                    break
                if key in item and item[key] != value:
                    skip_entry = True
                    break
        if skip_entry:
            continue

        entry = dict()
        # probably sensitive data, we opt-in here explicetly
        for i in ('username', 'color', 'email', 'fullname'):
            if i in item:
                entry[i] = item[i]
        ret.append(entry)

    if len(ret) == 0:
        msg = "user DB do not contain valid entry for given filter"
        raise ApiError(msg, http_code=404)

    return ret



def get(user_filter=None):
    path = app.config['CONF_USER_FILEPATH']
    data = load_data(path)
    return filter_data(data, user_filter)

{'fraction_non_alphanumeric': 0.07846277021617294, 'fraction_numerical': 0.005604483586869495, 'mean_word_length': 1.8494868871151653, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '178925', 'n_tokens_mistral': 732, 'n_tokens_neox': 696, 'n_words': 243}