Ejemplo de Acceso a myBus

#in this first part, we are going to seek any bus using the stop number 72 in order to test this bus with myBus

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 ID CLIENT’,‘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:

#now, we are going to use this bus number for getting data from myBus system

        myBusTest = results[‘busId’]

        printaccesing to bus Id…”+myBusTest

        urlbus = “https://mybus.emtmadrid.es:8073/rests”

        params=“?srv=DatosCoche&Paradas=99&bus=”+myBusTest

        aut_h = urllib2.HTTPPasswordMgrWithDefaultRealm()

        aut_h.add_password(None, urlbus,  “YOUR ID CLIENT”,  “YOUR PASS KEY”

        handler = urllib2.HTTPBasicAuthHandler(aut_h)

        opener = urllib2.build_opener(handler)

        urllib2.install_opener(opener)

        

        response = urllib2.urlopen(urlbus+params)

        results = response.read()

        print results

        #valueDict = xmltodict.parse(results)

        

print “end”