Crowdflower API-Python客户端
crowdflower的Python项目详细描述
用于与 CrowdFlowerAPI 和Python一起。
安装
从PyPI安装 `setuptools<;https://setuptools.readthedocs.io/>;`\
easy_install -U crowdflower
或者用`pip<;https://pip.pypa.io/>;`
pip install -U crowdflower
或者从 github,使用pip:
git+https://github.com/twosigma/ngrid
或者用setuptools:
自己构建源代码git clone https://github.com/peoplepattern/crowdflower.git cd crowdflower python setup.py develop
基本用法
导入方式:
import crowdflower
CrowdflowerAPI密钥有20个字符长;下面的一个只是 随机字符。(您可以在 make.crowdflower.com/account/user。)
conn = crowdflower.Connection(api_key='LbcxvIlE3x1M8F6TT5hN')
库将默认为一个名为 CROWDFLOWER_API_KEY如果此处未指定:
conn = crowdflower.Connection()
如果要缓存作业响应,如判断、属性和 标记,可以使用缓存初始化连接。 cache='filesystem'是当前支持的唯一选项,并且 将json文件序列化为/tmp/crowdflower/*。
conn = crowdflower.Connection(cache='filesystem')
循环浏览所有作业并打印标题:
for job in conn.jobs(): print job.properties['title']
创建新工单
使用一些新单位创建新工单:
data = [ {'id': '1', 'name': 'Chris Narenz', 'gender_gold': 'male'}, {'id': '2', 'name': 'George Henckels'}, {'id': '3', 'name': 'Maisy Ester'}, ] job = conn.upload(data) update_result = job.update({ 'title': 'Gender labels', 'included_countries': ['US', 'GB'], # Limit to the USA and United Kingdom # Please note, if you are located in another country and you would like # to experiment with the sandbox (internal workers) then you also need # to add your own country. Otherwise your submissions as internal worker # will be rejected with Error 301 (low quality). 'payment_cents': 5, 'judgments_per_unit': 2, 'instructions': 'some <i>instructions</i> html', 'cml': 'some layout cml, e.g., ' '<cml:text label="Sample text field:" validates="required" />', 'options': { 'front_load': 1, # quiz mode = 1; turn off with 0 } }) if 'errors' in update_result: print(update_result['errors']) exit() job.gold_add('gender', 'gender_gold')
为按需工作人员启动作业(默认):
job.launch(2)
启动内部员工的作业(沙盒):
job.launch(2, channels=['cf_internal'])
检查作业的状态:
print job.ping()
清除;删除由以上示例创建的所有作业:
for job in conn.jobs(): if job.properties['title'] == 'Gender labels': print 'Deleting Job#%s' % job.id print job.delete()
查看迄今为止收集的批注:
for row in job.download(): print row
示例
请参阅中的README.md。 `examples/<;https://github.com/peoplepattern/crowdflower/tree/master/examples>;。`_ 一个完整的垃圾邮件分类示例目录,使用 可用SMS Spam Collection。
调试/记录
要启用详细日志记录,请在脚本中使用以下命令:
import logging logging.basicConfig(level=logging.DEBUG)
动机
官方的Ruby client很难 使用,这是令人惊讶的,因为crowdflower api非常简单。
不是说CrowdFlower API 是所有的小马和彩虹,但所有的文件都在一个上面 佩奇,它做了它说的大部分。(尽管还有更多 你可以做的,除了记录的以外。)
因此,crowdflower api的瘦python客户端。
参考文献
Crowdflower博客是API的最终(但不完整)来源 文档:
- The main API documentation page -上次更新时间:2014年7月31日
- More info on the API -上次更新时间:2014年7月31日
- Details on using API webhooks -上次更新时间:2014年7月25日
- Rest API -上次更新时间:2014年8月11日
- API Request Examples -上次更新时间:2014年8月11日
- CML (CrowdFlower Markup Language) -上次更新时间:2014年8月12日
官方的源代码 ruby-crowdflower 项目在某些情况下也很有用。
这个包使用kennethreitzRequests到 通过http与crowdflower api通信。请求是Apache2 licensed。
支架
找到虫子了吗?想要新功能吗?File an issue!
贡献
我们热爱开源,并与更大的社区合作, 代码库更好!如果你有什么贡献,请把这个交出来 存储库,将更改提交到新分支,然后提交一个请求 请求返回此存储库(PeoplePattern/Crowdflower)。加速 合并拉取请求时,请遵循样式惯例 已经存在于存储库中。其中包括:
- 遵守PEP8
- 我们对每一个PEP8会议都不是很严格,但是我们有一个
很少有硬性要求:
- 四个空格缩进
- 无标签
- 无分号
- 没有通配符导入
- 没有尾随空格
- 大量使用docstrings
apache许可证2.0包含一个覆盖Contributor License Agreement的子句。
许可证
版权所有2014 People Pattern Corporation
在apache许可下授权,版本2.0(“许可证”);您可以 除非符合许可证,否则不要使用此文件。你可以获得 在
http://www.apache.org/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则软件 根据许可证分发是按“原样”分发的, 无任何明示或默示的保证或条件。 有关管理权限的特定语言和 许可下的限制。