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="")
Metadata
Release files for b2cloud 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| b2cloud-0.2.0.tar.gz | 12.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| b2cloud-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.2 kB
Release files / b2cloud-0.2.0.tar.gz
| Download URL | b2cloud-0.2.0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
99eb0152a034f7c3b8c65222385c981fb3a777b373b3be38b7dc32c6cf4e517b
|
|
BLAKE2b-256 checksum How to use checksums |
02edb2f5df4c977d8e62fa1563451de561b3a33d983a085ca5cf55a9ee95bd20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.9.16 Darwin/22.4.0
|
Release files / b2cloud-0.2.0-py3-none-any.whl
| Download URL | b2cloud-0.2.0-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11350915f567288b970faa70ea34da63daed8f4300ad2901687bffa551fa89e2
|
|
BLAKE2b-256 checksum How to use checksums |
21ac445484af956d216cee51d986c613fc5985f7f6eb45232016ef2f23da55e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.9.16 Darwin/22.4.0
|
Security for b2cloud 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.