<commit_before>from django.shortcuts import render
from django.http import JsonResponse
from thegamesdb.api import get_games_list, get_game


def _get_games_db_results(query):
    if query:
        return get_games_list(query)


def search(request):
    query = request.GET.get('q')
    results = _get_games_db_results(query)
    return render(request, 'thegamesdb/search.html', {
        'results': results,
        'query': query
    })


def search_json(request):
    query = request.GET.get('term')
    results = _get_games_db_results(query)
    return JsonResponse({
        'results': [
            {
                'text': u"{} ({}, {})".format(
                    result['game_title'], result['release_date'], result['platform']
                ),
                'id': result['id']
            } for result in results
        ],
        'more': False
    })


def detail(request, game_id):
    game = get_game(game_id)
    return JsonResponse(game)
<commit_msg>Avoid error when TGDB comes up with empty results<commit_after>from django.shortcuts import render
from django.http import JsonResponse
from thegamesdb.api import get_games_list, get_game


def _get_games_db_results(query):
    if query:
        return get_games_list(query)


def search(request):
    query = request.GET.get('q')
    results = _get_games_db_results(query)
    return render(request, 'thegamesdb/search.html', {
        'results': results,
        'query': query
    })


def search_json(request):
    query = request.GET.get('term')
    results = _get_games_db_results(query) or []
    return JsonResponse({
        'results': [
            {
                'text': u"{} ({}, {})".format(
                    result['game_title'], result['release_date'], result['platform']
                ),
                'id': result['id']
            } for result in results
        ],
        'more': False
    })


def detail(request, game_id):
    game = get_game(game_id)
    return JsonResponse(game)

{'fraction_non_alphanumeric': 0.12084592145015106, 'fraction_numerical': 0.0, 'mean_word_length': 2.504409171075838, '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': '4781936', 'n_tokens_mistral': 612, 'n_tokens_neox': 584, 'n_words': 133}