23
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonでヤマト運輸の荷物追跡

Posted at

Pythonを用いてヤマト運輸の荷物を追跡します。
使用しているmoduleは
requests : http://docs.python-requests.org/en/latest/
のみです。

このコードは下記APIを利用しています。提供者さんありがとうございます。
http://nanoappli.com/blog/archives/603

因みにこのコードはお問い合わせ番号を整数型であることを前提としています。string型などがでるとType-errorか何か出ると思います()

ヤマト運輸荷物追跡.py
#coding: utf-8

import requests

def GET_status(number):
    URL_JSON = 'http://nanoappli.com/tracking/api/%d.json' % number
    r = requests.get(URL_JSON)
    j = r.json()
    status = j['status']
    itemType = j['itemType']
    slipNo = j['slipNo']
    statusList = j['statusList']
    for status_ in statusList:
        date = status_['date']
        time = status_['time']
        placeName = status_['placeName']
        placeCode = status_['placeCode'];
        data_ =  u"""[最新状況]: %s
[配送物種別]: %s
[配送物伝票番号]: %s
[現在位置]: %s %s ([時刻] %s %s )
""" % (status, itemType, slipNo, placeName, placeCode, date, time)
        return data_

if __name__ == '__main__':
    number = input("> ")
    i = GET_status(number)
    print i
23
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?