<commit_before>import logging

from django.utils import simplejson

from google.appengine.api import memcache
from google.appengine.ext import db

from models import Team, Match, Event
from helpers.event_helper import EventHelper
from helpers.match_helper import MatchHelper

class ApiHelper(object):
    """Helper for api_controller."""
    @classmethod
    def getTeamInfo(self, team_key):
        """
        Return a Team dict with basic information.
        """
        memcache_key = "api_team_info_%s" % team_key
        team_dict = memcache.get(memcache_key)
        if team_dict is None:
            team = Team.get_by_key_name(team_key)
            if team is not None:
                team_dict = dict()
                team_dict["key"] = team.key().name()
                team_dict["team_number"] = team.team_number
                team_dict["name"] = team.name
                team_dict["nickname"] = team.nickname
                team_dict["website"] = team.website
                team_dict["event_keys"] = [a.event.key().name() for a in team.events]
                team_dict["location"] = team.address
                
                try:
                    team.do_split_address()
                    team_dict["location"] = team.split_address["full_address"]
                    team_dict["locality"] = team.split_address["locality"]
                    team_dict["region"] = team.split_address["region"]
                    team_dict["country"] = team.split_address["country"]
                except Exception, e:
                    logging.info("Failed to include Address for api_team_info_%s" % team_key)
                
                memcache.set(memcache_key, team_dict, 3600)
            else:
                return None
        return team_dict
    
    
    @classmethod<commit_msg>Better address building in API.<commit_after>import logging

from django.utils import simplejson

from google.appengine.api import memcache
from google.appengine.ext import db

from models import Team, Match, Event
from helpers.event_helper import EventHelper
from helpers.match_helper import MatchHelper

class ApiHelper(object):
    """Helper for api_controller."""
    @classmethod
    def getTeamInfo(self, team_key):
        """
        Return a Team dict with basic information.
        """
        memcache_key = "api_team_info_%s" % team_key
        team_dict = memcache.get(memcache_key)
        if team_dict is None:
            team = Team.get_by_key_name(team_key)
            if team is not None:
                team_dict = dict()
                team_dict["key"] = team.key().name()
                team_dict["team_number"] = team.team_number
                team_dict["name"] = team.name
                team_dict["nickname"] = team.nickname
                team_dict["website"] = team.website
                team_dict["event_keys"] = [a.event.key().name() for a in team.events]
                team_dict["location"] = team.address
                
                try:
                    team.do_split_address()
                    team_dict["location"] = team.split_address.get("full_address", None)
                    team_dict["locality"] = team.split_address.get("locality", None)
                    team_dict["region"] = team.split_address.get("region", None)
                    team_dict["country"] = team.split_address.get("country", None)
                except Exception, e:
                    logging.info("Failed to include Address for api_team_info_%s" % team_key)
                
                memcache.set(memcache_key, team_dict, 3600)
            else:
                return None
        return team_dict
    
    
    @classmethod
{'fraction_non_alphanumeric': 0.09349593495934959, 'fraction_numerical': 0.002168021680216802, 'mean_word_length': 1.9247226624405704, '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': '3670970', 'n_tokens_mistral': 1020, 'n_tokens_neox': 974, 'n_words': 225}