Easy-to-use Python interface for the OPIS RealtimePriceService Web Service
Setup is simple:
- Add your customer token to credentials.py
- Import desired function from opis.py
- Enjoy the dictionary output!
from opis import authenticate, getzipcoderesults
import credentials
user_ticket = authenticate(credentials.CUSTOMER_TOKEN)
results = getzipcoderesults(user_ticket, zip="90048")
The following fields will be returned for all web service methods:
{
"station_1":
{
"address_1": "7900 BEVERLY BLVD",
"address_2": None,
"brand_name": "United",
"city": "Los Angeles",
"diesel_date": None,
"diesel_id": "1",
"diesel_price": None,
"distance_to_station": None,
"latitude": "34.0760532131",
"longitude": "-118.3614844154",
"midgrade_date": "2017-06-27T18:43:46.627-04:00",
"midgrade_id": "4",
"midgrade_price": "3.09900000",
"phone": "(323)935-2322",
"premium_date": "2017-06-27T18:43:46.627-04:00",
"premium_id": "5",
"premium_price": "3.29900000",
"state": "CA",
"station_id": "314688",
"station_name": "UNITED OIL-APRO #2",
"unleaded_date": "2017-06-27T18:43:46.627-04:00",
"unleaded_id": "3",
"unleaded_price": "2.99900000",
"zip": "90048"
}
}
Configure service-area variables within tests.py and run:
python tests.py
โ๏ธ
Easily find the average price of gas in a ZIP Code:
from opis import authenticate, getzipcoderesults
import credentials
user_ticket = authenticate(credentials.CUSTOMER_TOKEN)
results = getzipcoderesults(user_ticket, 90048)
unleaded_prices = []
for i, result in enumerate(results, start=1):
unleaded_prices.append(float(results['station_{}'.format(i)]['unleaded_price']))
average_price = sum(unleaded_prices) / len(unleaded_prices)
print(average_price)
authenticate(customer_token)
getcitystatesortedresults(user_ticket, city, state, sort_product)
getlatlongresults(user_ticket, lat, long)
getlatlongsortedresults(user_ticket, lat, long, sort_product)
GetLatLongSortedWithDistanceResults
getlatlongsortedwithdistanceresults(user_ticket, sort_product, filter_distance,
distance, lat, long, user_lat, user_long)
getzipcoderesults(user_ticket, zip)
getzipcodesortedresults(user_ticket, zip, sort_product)