Diffbot API 的 Python 客户端。
项目描述
如何使用它:
>>> import diffbot
>>> json_result = diffbot.article('https://github.com', token='…')
上面的简单示例是使用diffbot.Client 类的快捷方式。
>>> import diffbot
>>> client = diffbot.Client(token='…')
>>> json_result = client.article('https://github.com')
以上调用是使用diffbot.api()函数和diffbot.Client.api方法的快捷方式:
>>> import diffbot
>>> client = diffbot.Client(token='…')
>>> json_result = client.api('article', 'https://github.com')
要将数据(文本或 HTML)发布到 API,请使用text或html 参数:
>>> import diffbot
>>> client = diffbot.Client(token='…')
>>> json_result = client.api('article', 'https://github.com', html='''
... <h1>Introducing GitHub Traffic Analytics</h1>
... <p>We want to kick off 2014 with a bang, so today we're happy to launch
... traffic analytics!</p>
... ''')
命令行界面:
$ python diffbot.py -h
usage: diffbot.py [-h] [-a] [-f FILE] api url token
positional arguments:
api API to call. One one of 'article', 'frontpage',
'product', 'image', 'analyze' or 'discussion'.
url URL to pass as the 'url' parameter.
token API key (token). Get one at https://www.diffbot.com/.
optional arguments:
-h, --help show this help message and exit
-a, --all Request all fields.
-f FILE, --file FILE File to read data from. Use '-' to read from STDIN.
$ python diffbot.py article https://github.com TOKEN
上述示例的输出:
{
"icon": "https://github.com:443/apple-touch-icon-144.png",
"sections": [
…
],
"title": "Build software better, together.",
"url": "https://github.com/"
}
特征:
Python 2+3 支持
谷歌应用引擎支持
请求支持(但不依赖)
通过pyflakes、pep8、flake8、pylint分数 10/10
简单和小型(1 个文件,<200 LOC)
命令行界面