import requests


def get_friends_locations(screen_name, bearer_token):
    """
    Gets json file from twitter using requests
    and returns locations and usernames of the account of screen_name
    :param screen_name: twitter username
    :param bearer_token: API twitter bearer token
    :return: dictionary, key is username, value is location
    """
    locations = {}
    base_url = "https://api.twitter.com/"
    search_headers = {
        'Authorization': 'Bearer {}'.format(bearer_token)
        }
    search_params = {
        'screen_name': '@'+screen_name,
        'count': 30
    }

    search_url = '{}1.1/friends/list.json'.format(base_url)
    response = requests.get(search_url, headers=search_headers, params=search_params)
    json_response = response.json()
    for user in json_response['users']:
        friend_name = user['name']
        friend_location = user['location']
        if friend_location and friend_name:
            locations[friend_name] = friend_location
    return locations