Skip to main content

ヤマト運輸株式会社が提供する送り状発行システムB2クラウドをpythonで利用するパッケージ

Project description

b2cloud

ヤマト運輸株式会社の『送り状発行システムB2クラウド』を操作して伝票を印刷するためのモジュールです。 利用にあたっては、ヤマトビジネスメンバーズのaccount情報が必要となります。

インストール

pip install b2cloud

コード例

履歴の取得

import b2cloud
import b2cloud.utilities

session = b2cloud.login('your customer_code', 'your customer_password')
dm = b2cloud.search_history(session, service_type='3')

for entry in dm['feed']['entry']:
    print(entry['shipment']['tracking_number'], entry['shipment']['consignee_name'])

新規に伝票を作成し、データに不備がないかチェックする

# 伝票情報を生成する
shipment = b2cloud.utilities.create_dm_shipment(
    shipment_date='2022/12/24',
    consignee_telephone_display='00-0000-0000',
    consignee_name='テスト',
    consignee_zip_code='8900053',
    consignee_address1='鹿児島県',
    consignee_address2='鹿児島市',
    consignee_address3='中央町10',
    consignee_address4='キャンセビル6階',
    consignee_department1='インターマン株式会社'
)

# データに不備がないかチェックする
res = b2cloud.check_shipment(session, shipment)
print(res)

e.g.
{'success': True, 'errors': []}

伝票の新規保存

# shipmentsをpost_new_checkonlyを通す
checked_feed = b2cloud.post_new_checkonly(session, [shipment])
# 伝票情報をB2クラウドに保存する
res = b2cloud.post_new(session, checked_feed)

保存した伝票をDM形式で印刷し各伝票毎にPDFファイルに保存する

# 保存済みのDM伝票を取得
dm_feed = b2cloud.get_new(session, params={'service_type':'3'})
# DM伝票形式(1シート8枚)で印刷
dm_pdf = b2cloud.print_issue(session,'3', dm_feed)
# 1伝票毎に分割する
pdfs = b2cloud.utilities.split_pdf_dm(dm_pdf)
for i in range(len(pdfs)):
    with open(f'dm_{i}.pdf', 'wb') as f:
        f.write(pdfs[i])

住所を伝票情報に変換する

住所正規化サービスAddressian(https://addressian.netlify.app/)のAPI Keyが必要です。

consignee_address = b2cloud.utilities.get_address_info(
                                                session=session,
                                                addressian_api_key='abcdefghijklmnopqrtsuvwxyz1234567890',
                                                address='鹿児島市中央町10キャンセビル6F'
                                            )
print(consignee_address)

e.g.
{
    "consignee_zip_code": "8900053",
    "consignee_address1": "鹿児島県",
    "consignee_address2": "鹿児島市",
    "consignee_address3": "中央町10",
    "consignee_address4": "キャンセビル6F"
}

pytest

パラメータでログイン情報やaddressian_api_keyを指定します。

※注意

テストを実行するとテスト伝票が発行されます。 テスト実行後は、B2クラウドWEBサイトにログインして「保存分の発行」や「発行済みデータの検索」からテストデータを削除することをお勧めします。

pytest コマンド例

pytest -q tests/test_01.py  --customer_code=0123456789 --customer_password=abcdefghi --addressian_api_key=abcdefghijklmnopqrtsuvwxyz1234567890

パラメーターの一覧

parser.addoption("--customer_code",      action="store", default="")
parser.addoption("--customer_password",  action="store", default="")
parser.addoption("--customer_cls_cocde", action="store", default="")
parser.addoption("--login_user_id",      action="store", default="")
parser.addoption("--addressian_api_key", action="store", default="")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

b2cloud-0.1.7.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

b2cloud-0.1.7-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file b2cloud-0.1.7.tar.gz.

File metadata

  • Download URL: b2cloud-0.1.7.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.9.12 Darwin/21.5.0

File hashes

Hashes for b2cloud-0.1.7.tar.gz
Algorithm Hash digest
SHA256 dad42fd74113f9b5e55a363072f1e4941e8ce19569ea9269148df2e210b1ab1e
MD5 1116581b9336cfa6141c71f9db94621b
BLAKE2b-256 b49111279f4c29a8078214ee66d61a9d8049b261f7776ac354cfc964c67d21f1

See more details on using hashes here.

File details

Details for the file b2cloud-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: b2cloud-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.9.12 Darwin/21.5.0

File hashes

Hashes for b2cloud-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 956617cd8963169025fb128d80d6aaef812d46f498ba27ef52cdda71271f3f0f
MD5 085526950d6e0e45fd975a8156556d91
BLAKE2b-256 defaa4a77664ba379a4b2160aa07aaf064460814633a364008c6d5c8063d382a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page