python 查詢珠海公交車到站情況(顯示距離版)

   最近珠海公交公司出了一個手機app查詢公交車,但是優化做得不好,老是感覺卡,不爽,自己無聊就寫了一個python版的,方便下珠海市民


# coding=utf8
from lxml import etree
bus=int(raw_input('請輸入公交站路線:'))
bus_zd=raw_input('請輸入公交車:')
url="http://zhgj.zhuhai.gd.cn:8090/BusTransfer/brewMobile/queryArrivalForetell?lineName=%s路&stationName=%s" % (bus,bus_zd)
tree=etree.parse(url)
root=tree.getroot()
if(root.__len__() > 3):
    start_bus = root[3][4].text
    end_bus = root[3][5].text
    now_bus = root[3][6].text
    you_bus =  root[3][9].text
    print u'%s  到  %s 路線' % (start_bus,end_bus)
    print u'公交車已經到%s站' % now_bus
    print u'距離您還有%s站' % you_bus
    print '#########################'
    h_start_bus = root[4][4].text
    h_end_bus = root[4][5].text
    h_now_bus = root[4][6].text
    h_you_bus =  root[4][9].text
    print u'%s  到  %s 路線' % (h_start_bus,h_end_bus)
    print u'公交車已經到%s站' % h_now_bus
    print u'距離您還有%s站' % h_you_bus
else:
    print u'您輸入的有誤'



執行看下結果:

[root@zh rh]# python bus.py
請輸入公交站路線:35
請輸入公交車:招商花園城
雲頂瀾山  到  跨境工業區 路線
公交車已經到招商花園城站
距離您還有0站
#########################
跨境工業區  到  雲頂瀾山 路線
公交車已經到隧道南站
距離您還有5站

實現了,但是還是不方便,應該在手機上面能實現就好,於是就找了很多資料,python fro iphone,但是安裝了,卻沒有lxml這個模塊,以失敗告終

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章