-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
79 lines (57 loc) · 2.05 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
import requests, json
from api_config import EDMUNDS_API_KEY, EDMUNDS_API_BASE
def get_nice_names(state, year, api_key):
uri = EDMUNDS_API_BASE + 'makes?state=' + state \
+ '&year=' + year \
+ '&view=basic&fmt=json&api_key=' + EDMUNDS_API_KEY
r = requests.get(uri)
if r.status_code == 200:
return r.json()['makes']
else:
print r.status_code
return []
def get_all_sedans(make, year):
uri = EDMUNDS_API_BASE + make + '/models?state=new' \
+ '&year=' + year \
+ '&category=Sedan&view=basic&fmt=json&api_key=' + EDMUNDS_API_KEY
r = requests.get(uri)
if r.status_code == 200:
return r.json()['models']
else:
print r.status_code
return []
def get_style_for_id(style_id):
uri = EDMUNDS_API_BASE + 'styles/' + style_id + '?view=full&fmt=json&api_key=' + EDMUNDS_API_KEY
r = requests.get(uri)
if r.status_code == 200:
return r.json()
else:
print r.status_code
return []
def get_other_details(style_id):
uri = EDMUNDS_API_BASE + 'styles/' + style_id + '/equipment?availability=standard&equipmentType=OTHER&fmt=json&api_key=' + EDMUNDS_API_KEY
r = requests.get(uri)
if r.status_code == 200:
return r.json()
else:
print r.status_code
return []
def get_sedan_style_ids(make, year):
rtn = []
for model in get_all_sedans(make, year):
for year in model['years']:
for style in year['styles']:
if style['id']:
rtn.append(str(style['id']))
return rtn
# print out basic make/model details for a given make and year
'''
for model in get_all_sedans(make, '2014'):
#print model['id']
for year in model['years']:
#print year
for style in year['styles']:
#print style
print str(model['id']) + ', ' + str(year['year']) + ', ' + str(style['id']) + ', ' + style['name']
'''