<commit_before>#! /usr/bin/python

import requests
import json

from config import EDMUNDS_KEY, EDMNUDS_SECRET

def get_styles(make, model, year):
    url = 'https://api.edmunds.com/api/vehicle/v2/{0}/{1}/{2}?fmt=json&api_key={3}'.format(make, model, year, EDMUNDS_KEY)
    r = requests.get(url)
    if r.status_code != 200:
        print 'Status', r.status_code, r.content
        return {}
    else:
        return json.loads(r.content)

def get_price(style_id):
    url = 'https://api.edmunds.com/v1/api/tmv/tmvservice/calculateusedtmv?styleid={0}&condition=Outstanding&mileage=25000&zip=07302&fmt=json&api_key={1}'.format(style_id, EDMUNDS_KEY)
    r = requests.get(url)
    if r.status_code != 200:
        print 'Status', r.status_code, r.content
        return {}
    else:
        return json.loads(r.content)

def get_average_price(make, model, year):
    styles = get_styles(make, model, year)
    # print json.dumps(styles, indent=2)<commit_msg>Added retry for 403 rate limiting errors<commit_after>#! /usr/bin/python

import requests
import json
import time

from config import EDMUNDS_KEY, EDMNUDS_SECRET

MAX_ATTEMPTS = 5

def get_styles(make, model, year, attempts = MAX_ATTEMPTS):
    url = 'https://api.edmunds.com/api/vehicle/v2/{0}/{1}/{2}?fmt=json&api_key={3}'.format(make, model, year, EDMUNDS_KEY)
    r = requests.get(url)
    if r.status_code == 403 and attempts > 0: # Retry
        time.sleep(1)
        return get_styles(make, model, year, attempts - 1)
    if r.status_code != 200:
        print 'Status', r.status_code, r.content
        return {}
    else:
        return json.loads(r.content)

def get_price(style_id, attempts = MAX_ATTEMPTS):
    url = 'https://api.edmunds.com/v1/api/tmv/tmvservice/calculateusedtmv?styleid={0}&condition=Outstanding&mileage=25000&zip=07302&fmt=json&api_key={1}'.format(style_id, EDMUNDS_KEY)
    r = requests.get(url)
    if r.status_code == 403 and attempts > 0: # Retry
        time.sleep(1)
        return get_price(style_id, attempts - 1)
    if r.status_code != 200:
        print 'Status', r.status_code, r.content
        return {}
    else:
        return json.loads(r.content)

def get_average_price(make, model, year):
    styles = get_styles(make, model, year)
    # print json.dumps(styles, indent=2)
{'fraction_non_alphanumeric': 0.137340939008337, 'fraction_numerical': 0.028960070206230804, 'mean_word_length': 3.5508982035928143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '2695122', 'n_tokens_mistral': 873, 'n_tokens_neox': 831, 'n_words': 163}