@csrf_exempt
def recommendations_service_api(request):
    '\n    Returns package recommendations for API POST call without authentication\n\n    arguments:\n        :request: POST request of application/json type\n\n    returns:\n        list of package recommendations\n    '
    if (request.method == 'POST'):
        try:
            json_data = json.loads(request.body)
        except json.JSONDecodeError:
            return HttpResponseBadRequest('Could not parse JSON.')
        try:
            dependencies = json_data['dependencies']
            language = json_data['language'].lower()
        except KeyError:
            return HttpResponseBadRequest('Required JSON keys: `dependencies`, `language`')
        except AttributeError as e:
            return HttpResponseBadRequest(f'Error casting language to lower(): {e}')
        if ((not isinstance(dependencies, list)) or (not dependencies)):
            return HttpResponseBadRequest(f'{language.capitalize()} dependencies must be non-empty and of type LIST (i.e. [...]).')
        if (language == PYTHON):
            dependencies = '\n'.join(dependencies)
        elif (language == JAVASCRIPT):
            formatted_dependencies_list = [(('"' + dep.replace('@', '":"')) + '"') for dep in dependencies]
            dependencies = ','.join(formatted_dependencies_list)
        else:
            return HttpResponseBadRequest(f'Language not supported: [{language}].')
        dependencies = github_util.parse_dependencies(dependencies, language)
        if ('max_recommendations' in json_data):
            recommended_dependencies = RECOMMENDER_SERVICE.get_recommendations(dependencies, json_data['max_recommendations'])
        else:
            recommended_dependencies = RECOMMENDER_SERVICE.get_recommendations(dependencies)
        output_recommended_dependencies = []
        for recommended_dependency in recommended_dependencies:
            d = dict()
            d['forPackage'] = recommended_dependency[0]
            d['recommendedPackage'] = recommended_dependency[1]
            d['url'] = recommended_dependency[2]
            d['pkgpkrScore'] = recommended_dependency[3]
            d['absoluteTrendScore'] = recommended_dependency[4]
            d['relativeTrendScore'] = recommended_dependency[5]
            d['boundedPopularityScore'] = recommended_dependency[6]
            d['boundedSimilarityScore'] = recommended_dependency[7]
            d['categories'] = recommended_dependency[8]
            d['displayDate'] = recommended_dependency[9]
            d['monthlyDownloadsLastMonth'] = recommended_dependency[10]
            output_recommended_dependencies.append(d)
        data = {'language': language, 'recommended_dependencies': output_recommended_dependencies}
        return HttpResponse(json.dumps(data), content_type='application/json')
    return HttpResponseNotAllowed(['POST'])
Returns package recommendations for API POST call without authentication

arguments:
    :request: POST request of application/json type

returns:
    list of package recommendations
@csrf_exempt
def recommendations_service_api(request):
    '\n    Returns package recommendations for API POST call without authentication\n\n    arguments:\n        :request: POST request of application/json type\n\n    returns:\n        list of package recommendations\n    '
    if (request.method == 'POST'):
        try:
            json_data = json.loads(request.body)
        except json.JSONDecodeError:
            return HttpResponseBadRequest('Could not parse JSON.')
        try:
            dependencies = json_data['dependencies']
            language = json_data['language'].lower()
        except KeyError:
            return HttpResponseBadRequest('Required JSON keys: `dependencies`, `language`')
        except AttributeError as e:
            return HttpResponseBadRequest(f'Error casting language to lower(): {e}')
        if ((not isinstance(dependencies, list)) or (not dependencies)):
            return HttpResponseBadRequest(f'{language.capitalize()} dependencies must be non-empty and of type LIST (i.e. [...]).')
        if (language == PYTHON):
            dependencies = '\n'.join(dependencies)
        elif (language == JAVASCRIPT):
            formatted_dependencies_list = [(('"' + dep.replace('@', '":"')) + '"') for dep in dependencies]
            dependencies = ','.join(formatted_dependencies_list)
        else:
            return HttpResponseBadRequest(f'Language not supported: [{language}].')
        dependencies = github_util.parse_dependencies(dependencies, language)
        if ('max_recommendations' in json_data):
            recommended_dependencies = RECOMMENDER_SERVICE.get_recommendations(dependencies, json_data['max_recommendations'])
        else:
            recommended_dependencies = RECOMMENDER_SERVICE.get_recommendations(dependencies)
        output_recommended_dependencies = []
        for recommended_dependency in recommended_dependencies:
            d = dict()
            d['forPackage'] = recommended_dependency[0]
            d['recommendedPackage'] = recommended_dependency[1]
            d['url'] = recommended_dependency[2]
            d['pkgpkrScore'] = recommended_dependency[3]
            d['absoluteTrendScore'] = recommended_dependency[4]
            d['relativeTrendScore'] = recommended_dependency[5]
            d['boundedPopularityScore'] = recommended_dependency[6]
            d['boundedSimilarityScore'] = recommended_dependency[7]
            d['categories'] = recommended_dependency[8]
            d['displayDate'] = recommended_dependency[9]
            d['monthlyDownloadsLastMonth'] = recommended_dependency[10]
            output_recommended_dependencies.append(d)
        data = {'language': language, 'recommended_dependencies': output_recommended_dependencies}
        return HttpResponse(json.dumps(data), content_type='application/json')
    return HttpResponseNotAllowed(['POST'])