<commit_before># coding=utf-8

from flask import jsonify
from flask import make_response
from os import path
import json
from api.helpers import make_error

parties = []
lookup = {}

with open(path.dirname(__file__) + '/../../data/parties.json', 'r') as f:
    parties = json.loads(f.read())
    for index, party in enumerate(parties):
        lookup[party['id']] = index

def get_parties():
    print 'getting mps!'
    response = jsonify(parties)
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
    response.headers.add('Access-Control-Allow-Methods', 'GET')
    return response

def get_party_by_id(party_id):
    if party_id not in lookup:
        return make_error('Not found')

    party_index = lookup[party_id]
    response = jsonify(parties[party_index])
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
    response.headers.add('Access-Control-Allow-Methods', 'GET')
    return response<commit_msg>Backend: use make_json_response helper for parties endpoint<commit_after># coding=utf-8

from flask import jsonify
from flask import make_response
from os import path
import json
from api.helpers import make_json_response, make_error

parties = []
lookup = {}

with open(path.dirname(__file__) + '/../../data/parties.json', 'r') as f:
    parties = json.loads(f.read())
    for index, party in enumerate(parties):
        lookup[party['id']] = index

def get_parties():
    print 'getting mps!'
    return make_json_response(parties)

def get_party_by_id(party_id):
    if party_id not in lookup:
        return make_error('Not found')

    party_index = lookup[party_id]
    return make_json_response(parties[party_index])
{'fraction_non_alphanumeric': 0.126775956284153, 'fraction_numerical': 0.001092896174863388, 'mean_word_length': 4.261494252873563, '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': '4807978', 'n_tokens_mistral': 570, 'n_tokens_neox': 566, 'n_words': 136}