Pythonは簡単な宅配便検索を実現

5845 ワード

#coding:UTF-8
#   100 API
#   : [email protected]

import requests
import urllib

#   :         
def GetComName(comCode):
    if comCode=='shentong':
        return '    '
    elif comCode=='zhontong':
        return '    '
    elif comCode=='ems':
        return 'EMS'
    elif comCode=='huitongkuaidi':
        return '    '
    else:
        return comCode

#   :      
def GetStateText(num):
    if num==0:
        return '   '
    elif num==1:
        return '  '
    elif num==2:
        return '  '
    elif num==3:
        return '   '
    elif num==4:
        return '    '
    elif num==5:
        return '   '
    elif num==6:
        return '   '

p = {}
p['text'] = input("         : ")  #  : 227728570825
autoComNum = requests.get("http://www.kuaidi100.com/autonumber/autoComNum", params=p)
com = autoComNum.json()


if com['auto'] == []:
    print("           !")

else:
    print("
---------------- ------------------
"
) i=0 for this in com['auto']: i = i + 1 print( str(i) + ". " + GetComName(this['comCode']) + "
"
) num = input(" : ") print("
---------------- , ... ------------------
"
) data = {} data['type'] = com['auto'][int(num)-1]['comCode'] data['postid'] = p['text'] data['valicode'] = '' data['id'] = 1 data['temp'] = '0.14881871496191512' query = requests.get("http://www.kuaidi100.com/query", params=data) res = query.json() print("
--> "
+ res['nu']) print("
--> "
+ GetComName(res['com'])) print("
--> "
+ GetStateText(int(res['state']))) print("
---------------- ------------------
"
) for this in res['data']: print(this['time'] + "\t" + this['context'] + "
"
)

転載先:http://blog.csdn.net/sabrecode/article/details/75094985