锌电子商务包装材料API(锌.IO)
Zinc的Python项目详细描述
欢迎来到锌
Zinc是用于进行电子商务采购的api。这个包允许您轻松访问api并通过命令行在amazon上进行购买。它还提供了锌api的包装器,可以很容易地在python代码中使用。
- 模块功能:
- 用于从命令行购买Amazon商品的交互式向导
- 从json文件读取订单信息并下订单的简单订单脚本
- python模块,允许您在zinapi之上编写自己的脚本
快速启动
要快速启动,您可以克隆repo或使用pip python包管理器。:
pip install zinc
(如果出现错误,可能需要使用sudo pip install zinc
)。一旦安装好锌模块,就可以像这样开始使用:
python -m zinc
这将打开一个交互式向导界面,您可以使用make amazon购买。按照向导中的说明操作,您就可以直接从您的终端进行购买了!
cli选项
还有其他使用zinc cli的方法。您可以创建一个json文件来存储您的发货和帐单信息您可以运行python -m zinc -h
以获取可使用命令的帮助例如,我可能拥有包含以下内容的文件~/.zincrc
:
{ "shipping_address": { "first_name": "Tim", "last_name": "Beaver", "address_line1": "77 Massachusetts Avenue", "address_line2": "", "zip_code": "02139", "city": "Cambridge",· "state": "MA", "country": "US" }, "billing_address": { "first_name": "Alyssa", "last_name": "Hacker", "address_line1": "77 Massachusetts Avenue", "address_line2": "", "zip_code": "02139", "city": "Cambridge",· "state": "MA", "country": "US" } }
然后,我可以使用指向此传送地址文件的-f
选项运行cli,这样就不必在交互式向导中再次输入传送地址:
python -m zinc -f ~/.zincrc
如果您愿意,可以包括信用卡信息(我们在examples/sample_information.json
中有一个示例供参考),但我们强烈建议您不要包括它。将信用卡信息明文留在硬盘上是个坏主意。
examples
文件夹有一个示例文件,其中包含可以尝试的假预填充信息。不过,你不能用它完成全部购买,因为它是一个伪造的信用卡号码要使用假信息运行向导,您可以执行以下操作:
python -m zinc -f examples/sample_information.json
简单顺序
如果您不喜欢通过交互式cli完成订单的制作过程,也可以使用zinc simple order模块。这是一个python模块,允许您通过在python字典或json文件中预先指定所有必需字段来进行排序。
您可以在examples/simple_order.json
中看到一个简单订单格式的示例,如下所示:
{ "client_token": "public", "retailer": "amazon", "product_id": "B007JR5304", "quantity": 1, "shipping_address": { "first_name": "Ben", "last_name": "Bitdiddle", "address_line1": "77 Massachusetts Avenue", "address_line2": "", "zip_code": "02139", "city": "Cambridge",· "state": "MA", "country": "US" }, "is_gift": false, "customer_email": "benbitdiddle@gmail.com", "shipping_preference": "cheapest", "payment_method": { "number": "5555555555554444", "security_code": "123", "expiration_month": 1, "expiration_year": 2015 }, "billing_address": { "first_name": "Alyssa", "last_name": "Hacker", "address_line1": "84 Massachusetts Ave", "address_line2": "", "zip_code": "02139", "city": "Cambridge",· "state": "MA", "country": "US" } }
一旦将其写进json文件中,就可以指定-s
选项(用于简单顺序),然后可以运行:
python -m zinc -s -f examples/simple_order.json
要进行简单的订购,只需预先填充所有相关信息,如送货地址、帐单地址、付款方式信息等,product_id
字段对应于Amazon Standard Identification Number (ASIN),可以在Amazon产品url中找到您还需要设置shipping_preference
字段,这将在下一节中解释。
运输方法
对于shipping_preference
项目,您可以为项目的发货方式设置不同的首选项。可用的首选项是:
cheapest
:选择最便宜的运输方式second
:选择第二天发货standard
:选择标准运输方法
python用法
除了使用cli,还可以将zinc
模块导入到一个python脚本中。这允许您定制和自动化您的亚马逊购买。您可以使用ZincSimpleOrder
类轻松访问锌api。您可以查看examples/simple_order_example.py
脚本以了解如何使用它(复制如下):
from zinc import ZincSimpleOrder simple_order = ZincSimpleOrder() result = simple_order.process({ "client_token": "public", "retailer": "amazon", "product_id": "B007JR5304", "quantity": 1, "shipping_address": { "first_name": "Ben", "last_name": "Bitdiddle", "address_line1": "77 Massachusetts Avenue", "address_line2": "", "zip_code": "02139", "city": "Cambridge",· "state": "MA", "country": "US" }, "is_gift": false, "customer_email": "benbitdiddle@gmail.com", "shipping_preference": "cheapest", "payment_method": { "number": "5555555555554444", "security_code": "123", "expiration_month": 1, "expiration_year": 2015 }, "billing_address": { "first_name": "Alyssa", "last_name": "Hacker", "address_line1": "84 Massachusetts Ave", "address_line2": "", "zip_code": "02139", "city": "Cambridge",· "state": "MA", "country": "US" } }) print result
您可以查看一个示例python脚本,该脚本同时处理来自python文件的订单。脚本在examples/multi_process.py
中
高级python用法
如果您想对api获得更多的控制,可以使用ZincRequestProcessor
类来发出请求。ZincRequestProcessor
类的process
方法允许您对zinAPI进行任何调用并等待响应。例如,您可以执行以下操作:
from zinc import ZincRequestProcessor payload = { "client_token": "public", "retailer": "amazon", "product_url": "http://www.amazon.com/gp/product/0394800761" } result = ZincRequestProcessor.process("variant_options", payload) print result
process
方法返回一个python字典,其中包含锌API对您的请求的响应运行上一个脚本将打印出以下内容:
{ 'product_url': 'http://www.amazon.com/gp/product/0394800761', '_created_at': '2014-01-24T21:59:12.755Z', '_type': 'variant_options_response', 'variant_options': [{ '_type': 'variant_option', '_id': '52e2e230ef2840020000020a', 'product_id': '0394800761', 'unit_price': '1149', 'dimensions': [] }], 'retailer': 'amazon' }
检查Zinc API documentation以查看所有可能的api调用。在examples/request_processor_example.py
中给出了一个使用ZincRequestProcessor
类放置整个顺序的示例。
联系人
如果您想了解更多有关锌的信息,或以自动方式在亚马逊上下大量订单,请联系<;support@zinc.io>;。我们已经建立了基础设施来帮助你! nn