Ejemplo de acceso Opendata

This sample shows how to access at Openbus API site and more specific for getting time arrival at stop using GetArriveStop method (see full documentation about this service on web site http://opendata.emtmadrid.es, section services)

import urllib

import urllib2

from VEUtils.pysimplesoap import client

from VEUtils.pysimplesoap.client import SoapClient

import  VEUtils.simplejson as json





useragent = Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)’

params = {‘idClient’ : ‘YOUR idClient’,‘passKey’ : ‘YOUR passKey’,‘idStop’ : stopFindBusTest}

headers = { ‘User-Agent’ : useragent,‘Content-type’:‘application/x-www-form-urlencoded }

data = urllib.urlencode(params)

req = urllib2.Request(urlGetFindBusTest, data, headers)

response = urllib2.urlopen(req)

results = response.read()

resultJson = json.loads(results)

if resultJson.has_key(‘arrives’):

    resultJsonbus = resultJson[‘arrives’]

    for results in resultJsonbus:

        print results