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





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”


        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)



        response = urllib2.urlopen(urlbus+params)

        results = response.read()

        print results

        #valueDict = xmltodict.parse(results)


print “end”