Powering a Price Widget

Woman powering the gears of the machine

Introduction

The python scripts below are written with Python 3.7, but many of them will work with other versions of python. If you don't have python installed you can get it here.

Our API is also available for general use from the following third parties:

Connect on RapidAPI
 

Encouraging the customer to buy that car

In this example we will retrieve the data needed to populate a widget on a dealer's site that will encourage a customer to buy that vehicle. We can create a simple price widget telling the customer the car is a good deal, but we can also create widgets that create urgency and encourage the customer to buy that vehicle now before someone else does.

The widget will use our pricing and sales velocity data to conditionally frame the vehicle in the best light. For example, the widget might highlight a low price on the vehicle compared to similar vehicles, that similar vehicles are in high demand, or that there are few similar vehicles nearby.

Below are a few examples of what can be powered with our Automotive API.

 
Your Market Report
Low Price!
This
is priced
% lower than average.
 
Your Market Report
In Demand!
This
sells
x faster than average.
 
 
Your Market Report
Running Out!
This
has
% lower market supply than average.
 
Your Market Report
Popular!
The
is the #
top seller near you.
 

Getting the data

For these widgets we will first retrieve some stats for our region to compare against the specific vehicles we want a widget for. After that we will find favorable features to highlight and assign those features to the vehicle's widgets.

This example assumes you have already set up your environment as discussed on the API Quick Start Page and have retrieved your access token.

 

Low Price Widget


#Here we compare the price of a new vehicle against the average 
#new price in the region.

#for this example we will use a hard coded brand and region name
from cisapi import CisApi
api=CisApi()
brandName="Ford"
regionName="REGION_SOUTHERN_CALIFORNIA"

myModelName="F-150"
myPrice=12345
myDiscount=1

#make get request to "/listPrice" endpoint
saleResp=api.listPrice(brandName, regionName)

#print(saleResp)
salesData=saleResp["data"]

#for this endpoint salesData is a list of dictionaries
for model in salesData:
    if(model["name"]==myModelName and float(model["average"])!=0):
        myDiscount=myPrice/float(model["average"])
        break
adj="lower"
if(myDiscount>1):
    adj="higher"

print("This "+myModelName+" is priced "+str((1-myDiscount)*100)+"% "
    +adj+" than average.")

 

In Demand Widget


#Here we compare the average time to sell against the region average

#for this example we will use a hard coded brand and region name
from cisapi import CisApi
api=CisApi()
brandName="Ford"
regionName="REGION_SOUTHERN_CALIFORNIA"

myModelName="F-150"


#get the list of brand names
brandResp=api.getBrands()
brandNames=brandResp["data"]


daysToSellData={}
#make get requests to "/daysToSell" endpoint
for brandName in brandNames:
    saleResp=api.daysToSell(brandName, regionName)

    #print(saleResp)
    salesData=saleResp["data"]
    daysToSellData[name]=salesData

daysToSellTotal=0
daysToSellCount=0
myDaysToSell=0

#loop through the data and calculate the average time for all models to sell
for brand in salesData.keys():
    for model in salesData[brand]:
        if(model["name"]==myModelName):
            myDaysToSell=float(model["average"])

        daysToSellTotal+=float(model["average"])
        daysToSellCount+=1

averageDaysToSell=daysToSellTotal/daysToSellCount
diff=averageDaysToSell/myDaysToSell

adj="faster"
if(diff<1):
    adj="slower"

print("This "+myModelName+" sells "+str(diff)+"x "+adj+" than average.")

 

Running Out Widget


#Here we compare the average vehicle supply against the region average

#for this example we will use a hard coded brand and region name
from cisapi import CisApi
api=CisApi()

brandName="Ford"
regionName="REGION_SOUTHERN_CALIFORNIA"

myModelName="F-150"


#get the list of brand names
brandResp=api.getBrands()
brandNames=brandResp["data"]


daysSupplyData={}
#make get requests to "/daysSupply" endpoint
for name in brandNames:
    saleResp=api.daysSupply(brandName=name, regionName=regionName)

    #print(saleResp)
    salesData=saleResp["data"]
    daysSupplyData[name]=salesData

daysSupplyTotal=0
daysSupplyCount=0
mySupply=0

#loop through the data and calculate the average supply for all models
for brand in salesData.keys():
    for model in salesData[brand]:
        if(model["name"]==myModelName):
            mySupply=float(model["regionAverage"])

        daysSupplyTotal+=float(model["regionAverage"])
        daysSupplyCount+=1

averageDaysSupply=daysSupplyTotal/daysSupplyCount
diff=mySupply/averageDaysSupply

adj="lower"
if(diff>1):
    adj="higher"

print("This "+myModelName+" has "+str((1-diff)*100)+"% "
    +adj+" market supply than average.")

Popular Widget


#Here we retrieve the top model list for a region and see where
#our vehicle ranks in it

#for this example we will use a hard coded model and region name
from cisapi import CisApi
api=CisApi()
regionName="REGION_SOUTHERN_CALIFORNIA"
myModelName="F-150"

#make get requests to "/topModels" endpoint
saleResp=api.topModels(regionName)

#print(saleResp)
salesData=saleResp["data"]

myRank=0

#salesData is a list of dictionaries
#loop through the data and find our model's rank
count=1
for model in salesData:
    if(model["modelName"]==myModelName):
        myRank=count
        break
    count+=1

print("The "+myModelName+" is the #"+str(myRank)+
    " top seller near you.")