Giter VIP home page Giter VIP logo

opis-python-api's Introduction

OPIS RealtimePriceService Web Service Python API

Easy-to-use Python interface for the OPIS RealtimePriceService Web Service

Getting Started

Setup is simple:

  • Add your customer token to credentials.py
  • Import desired function from opis.py
  • Enjoy the dictionary output!

Quickstart

from opis import authenticate, getzipcoderesults
import credentials

user_ticket = authenticate(credentials.CUSTOMER_TOKEN)

results = getzipcoderesults(user_ticket, zip="90048")

Sample Output

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"
   }
}

Running the tests

Configure service-area variables within tests.py and run:

python tests.py

โœ”๏ธ

Extended Example

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)

Available Methods

Authenticate

 authenticate(customer_token)

GetCityStateSortedResults

 getcitystatesortedresults(user_ticket, city, state, sort_product)

GetLatLongResults

 getlatlongresults(user_ticket, lat, long)

GetLatLongSortedResults

 getlatlongsortedresults(user_ticket, lat, long, sort_product)

GetLatLongSortedWithDistanceResults

 getlatlongsortedwithdistanceresults(user_ticket, sort_product, filter_distance, 
                                     distance, lat, long, user_lat, user_long)

GetZipCodeResults

 getzipcoderesults(user_ticket, zip)

GetZipCodeSortedResults

  getzipcodesortedresults(user_ticket, zip, sort_product)

Dependencies ๐Ÿ‘

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.