README

Stubhub API

A Python wrapper for the stubhub inventory search API. You can see the full tutorial in the Stubhub API.ipynb

png

Getting Started

from stubhub_scraper import St

import pandas as pd
import numpy as np

## Enter user's API key, secret, and Stubhub login
app_token = '7131e534-bbec-374f-b1e4-1bdf6909a8ee'
consumer_key = 'jC475_MWRt6VV0aRz6nhA4Kpfloa'
consumer_secret = 'U7bW44Spj64CDYwUQSofJaMh1zka'
stubhub_username = ''
stubhub_password = ''
    
st = St(app_token,consumer_key,consumer_secret,stubhub_username,stubhub_password)

b'{"access_token":"254gce9e-3abd-3274-9d1f-13b7c3bf96b2","refresh_token":"1fdrf277-ac54-3d8d-b59b-58aa1482f7f4","scope":"default","token_type":"Bearer","expires_in":14846462}'

If authentication is succesfull you will see a message similar to above with your access token.

Single event

# San Antonio at Golden State game on March 19th 2018 
listings = st.get_listings(103138286,pages=True)
listings[0]
{'currentPrice': 46.9,
 'dirtyTicketInd': False,
 'listingId': 1314761532,
 'listingPrice': 37.0,
 'quantity': 2,
 'retrieveTime': '2018-03-17 20:21:08',
 'row': '14',
 'score': 0.0,
 'seatNumbers': '1;2',
 'sectionId': 127168,
 'sectionName': 'Balcony Corner 229',
 'sellerSectionName': '229',
 'zoneId': 7453,
 'zoneName': 'Balcony Corner'}
# Number of listings
len(listings)
298

listings is a list of dictionaries one of which you can see above. You can convert it to a dataframe and save as a csv.

listings = pd.DataFrame(listings)
listings.head()
listings.to_csv('SpursvsWarriors 2018-3-19.csv')
currentPricedirtyTicketIndlistingIdlistingPricequantityretrieveTimerowscoreseatNumberssectionIdsectionNamesellerSectionNamezoneIdzoneName
046.90False131476153237.0022018-03-17 20:21:08140.01;2127168Balcony Corner 2292297453Balcony Corner
150.49False131438585139.9922018-03-17 20:21:08130.020;21127149Balcony Baseline 2012017454Balcony Baseline
250.50False128445130440.0022018-03-17 20:21:08130.013;14127156Balcony Corner 204Balcony Corner 2047453Balcony Corner
356.50False131443727845.0032018-03-17 20:21:08180.0General Admission127166Balcony Corner 2272277453Balcony Corner
457.70False131474415446.0022018-03-17 20:21:08150.07;8127166Balcony Corner 2272277453Balcony Corner

Multiple events

To download listings for multiple events use get_listings_by_event function that takes the events parameter which is a pandas dataframe with event name and id in the following format.

events = pd.read_csv('flyers events 2018.csv')
events
EventEventid
0Washington Capitals 3/18/2018103045481
1New York Rangers 3/22/2018103045437
2Boston Bruins 4/1/2018103045191
3Carolina Hurricanes 4/5/2018103045229
4New York Rangers 4/7/2018103045439

Let's get listings for the rest of Philadelphia Flyers home games in 2017-2018 season.

flyers = st.get_listings_by_event(events)
Event: New York Rangers 4/7/2018: : 5it [00:22,  4.52s/it]    

Done getting listings by event.


flyers.head()
currentPricedirtyTicketIndlistingIdlistingPricequantityretrieveTimerowscoreseatNumberssectionIdsectionNamesellerSectionNamezoneIdzoneNameEventDate
058.30False131473357346.5022018-03-17 20:21:20120.07;830197Mezzanine Goal 219AUPPER:219A7747Mezzanine GoalWashington Capitals 3/18/20183/18/2018
158.90False131452084347.0022018-03-17 20:21:20130.0NA30190Mezzanine Goal 210AUPPER:210A7747Mezzanine GoalWashington Capitals 3/18/20183/18/2018
258.90False131447107647.0022018-03-17 20:21:2080.015;1630199Mezzanine Goal 221UPPER:2217747Mezzanine GoalWashington Capitals 3/18/20183/18/2018
358.90False131471845447.0022018-03-17 20:21:20110.0NA30181Mezzanine Goal 205UPPER:2057747Mezzanine GoalWashington Capitals 3/18/20183/18/2018
460.09False131400863847.9922018-03-17 20:21:20110.011;1230193Mezzanine Goal 217UPPER:2177747Mezzanine GoalWashington Capitals 3/18/20183/18/2018
pd.unique(flyers['Event'])
array(['Washington Capitals 3/18/2018', 'New York Rangers 3/22/2018',
       'Boston Bruins 4/1/2018', 'Carolina Hurricanes 4/5/2018',
       'New York Rangers 4/7/2018'], dtype=object)

png

Let's also look at the number of listings.

png

Below is a good visual to see how spread out the prices by event are.

png

Reference

get_listings(eventid, pages=False) - Get listings using Stubhub API.

Parameters:

  • eventid (int) - eventid taken from the Stubhub event url.
  • pages (bool) - if True paginate to get all listings. If False get 200 listings.

get_listings_by_event(events) - Given the list of events and event ids retrieve all the listings for each event .

Parameters:

  • events (pandas DataFrame) - a pandas dataframe of events and event ids taken from stubhub.

Resources