<commit_before>import json

import flask
import requests


class WPView(object):
    def __init__(self, data):
        self.data = data['post']

    @property
    def hero(self):
        hero_id = self.data['custom_fields']['related_hero'][0]
        hero_url = "http://your.wordpress.domain/api/get_post/?post_id=" + hero_id + "&post_type=cfpb_hero"
        response = requests.get(hero_url)
        hero_data = json.loads(response.text)
        return hero_data['post']

    @property
    def related_links(self):
        custom_fields = self.data['custom_fields']
        related =[]
        for x in xrange(0,4):
            key = 'related_link_%s' % x
            if key in custom_fields:
                related.append(custom_fields[key])
        return related

def do_lookup():
    request = flask.request    
    json_url = "http://your.wordpress.domain/view" + request.path + "?json=1"
    response = requests.get(json_url)
    data = json.loads(response.text)
    return WPView(data)
<commit_msg>Restrict related links to 5 not 4.<commit_after>import json

import flask
import requests


class WPView(object):
    def __init__(self, data):
        self.data = data['post']

    @property
    def hero(self):
        hero_id = self.data['custom_fields']['related_hero'][0]
        hero_url = "http://your.wordpress.domain/api/get_post/?post_id=" + hero_id + "&post_type=cfpb_hero"
        response = requests.get(hero_url)
        hero_data = json.loads(response.text)
        return hero_data['post']

    @property
    def related_links(self):
        custom_fields = self.data['custom_fields']
        related =[]
        for x in xrange(0,5):
            key = 'related_link_%s' % x
            if key in custom_fields:
                related.append(custom_fields[key])
        return related

def do_lookup():
    request = flask.request    
    json_url = "http://your.wordpress.domain/view" + request.path + "?json=1"
    response = requests.get(json_url)
    data = json.loads(response.text)
    return WPView(data)

{'fraction_non_alphanumeric': 0.12235872235872236, 'fraction_numerical': 0.004914004914004914, 'mean_word_length': 2.675090252707581, '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': '643858', 'n_tokens_mistral': 652, 'n_tokens_neox': 635, 'n_words': 130}