jmcarp / betfair.py

A Python wrapper for the Betfair API
MIT License
103 stars 76 forks source link

Support bet fairs navigation data for applications #47

Open goetzk opened 9 years ago

goetzk commented 9 years ago

While I only have medium term plans for the data provided, i thought support for the bet fair supplied navigation data might be a handy thing to have in the library.

https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Navigation+Data+For+Applications

primal100 commented 8 years ago

This is a basic start to retrieving the data:

  import StringIO
  import gzip

  self.navigationurl = 'https://api.betfair.com/exchange/betting/rest/v1/en/navigation/menu.json'

  def downloadNavigationData(self):
        request = urllib2.Request(self.navigationurl)
        request.add_header('Accept-encoding', 'gzip')
        request.add_header("X-Application", self.app_key)
        request.add_header("X-Authentication", self.session_token)
        opener = urllib2.build_opener()
        f = opener.open(request)
        c_data = f.read()
        c_stream = StringIO.StringIO(c_data)
        gzipper = gzip.GzipFile(fileobj=c_stream)
        data = gzipper.read()
        json_data = json.loads(data)
        return json_data