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

  

      

stopFindBusTest=72

urlGetFindBusTest=“https://openbus.emtmadrid.es:9443/emt-proxy-server/last/geo/GetArriveStop.php”

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