用于blackcurve的api的易于使用的python接口
blackcurve的Python项目详细描述
blackcurve python api库
API文档
可以找到blackcurve端点的文档here。
要求
- Python2.7+
- Requestspython v2.0或更高版本的http库。
安装
$ pip install blackcurve
基本用法
启动连接
您只需要您的子域和访问令牌就可以开始了
fromblackcurve.apiimportBlackCurveAPIbc=BlackCurveAPI({{subdomain}},{{access_token}})
重新加载访问令牌
需要一个新的访问令牌,还是只是放错了旧的?
bc=BlackCurveAPI({{subdomain}})token=bc.get_access_token({{client_key}},{{client_secret}})print(token)
这也将用新的令牌更新blackcurveapi实例,以便您可以立即继续处理请求。
获取价格
获取当前价格列表
# get all the pricesbc.prices().all()# get all pricesprices=bc.prices().all()print('You have {} prices'.format(len(prices)))# get a price for a single product by Product IDbc.prices().find('UK42')# filter specific product columnsbc.prices(columns=['Price','Product ID']).all()# filter geographybc.prices(geography='UK').all()# filter by column value -- price >= 5bc.prices(price_gte=5).all()
数据源信息
获取有关数据源的列和数据类型信息
# get all the data sourcesdata_sources=bc.data_sources_info().all()print(data_sources)# get a single data sourcesales_history=bc.data_sources_info().find('Sales History')print(sales_history)# create a new column sales_history['New Order Column']='Integer'sales_history.save()# delete a columndelsales_history['New Order Column']sales_history.save()
数据源
获取给定源中所有数据的列表
# get all of the data from sales historybc.data_sources('Sales History').all()# get just the volume and product id columns in sales historybc.data_sources('Sales History',columns=['Volume','Product ID']).all()# filter by column value -- price >= 5bc.data_sources('Sales History',price_gte=5).all()# get a generator for all the pages returned in sales history (lazy requests)sales_history=bc.data_sources('Sales History').all()page=1forxinsales_history:print('Page %s of Sales History: %s'%(page,x))page+=1# get a Transactions system idsales_history=bc.data_sources('Sales History').all()first_sale=sales_history[0]first_sale_id=first_sale.id# find a transaction by a system idfirst_sale=bc.data_sources('Sales History').find(first_sale_id)# edit a column on a transactionfirst_sale['Price']=42.00first_sale.save()# create a new transactionsales_history=bc.data_sources('Sales History')sales_history.create({'Product ID':'UK54321','Profit':7.77,'Revenue':6.66,'Volume':1,'Price':3.33,'Transaction Date':datetime.date.today()})# get all transactions for a given product idtransactions=bc.data_sources('Sales History',product_id='UK54321').all()print('There are {} transactions for product - UK54321'.format(len(transactions)))# change the price of a product [must use the kwarg product_id as .find() is only for system id] product=bc.data_sources('Product Inventory',product_id='UK54321').all()[0]product['Price']=55.99product.save()
地理和货币
获取地理位置和货币的关联数据列表
# get a list of all of the geography dataall_geographies=bc.geographies().all()# get a specific geographywebsite_uk=bc.geographies('Website UK').all()# get a list of all currenciesall_currencies=bc.currencies().all()