黑客新闻api的非官方python包装
haxor的Python项目详细描述
#haxor
[![特拉维斯](https://img.shields.io/travis/avinassh/haxor.svg)](http://travis ci.org/avinassh/haxor)
[![工作服](https://img.shields.io/covertalls/avinassh/haxor.svg)](https://covertalls.io/r/avinassh/haxor?分支=主)
[![版本](https://img.shields.io/pypi/v/haxor.svg)(https://pypi.python.org/pypi/haxor/)
[![支持](https://img.shields.io/pypi/pyversions/haxor.svg)](https://pypi.python.org/pypi/haxor/)
![许可证](https://img.shieldeshields.io/pypi/l/haxor.svg)
>官方黑客新闻api的非官方的python包装器。
安装
======
`` python
pip install haxor
```
=
===
==
进口hackernews
hn=hackernews()
```
item.title
"My YC app:Dropbox-扔掉你的USB驱动器"
"item.item"type
"story"
"item.kids"
"[8952、9224、8917,…]
"```
",因为大多数结果都返回为整数ID(如上面的item.kids),这些结果需要进一步迭代。不要自己这样做,而是使用"expand"标志按ID获取面向对象的详细项目信息:
``python
item=hn.get\item(8863,expand=true)
项目。通过
\lt;hackernews.user:dhouston>;
````
>查询项目ID列表:
```python
````````````````````
``items=hn。通过项目ID([8863,37236,2345])
>项目。通过项目ID([8863,37236,2345,37236,2345;[8863,37236,2345])
>>项目
>>>>>项目
===>>>[<;黑客。项目:8863;hackernews.item:8863-我的yc app:dropbox:dr.项目:
#37236-none>;,<;hackernews.item:2345-百思买骗局。>;]
````
使用"item_type"筛选器具体选择"story"、"comment"、"job"或"poll"项:
``python
items=hn.get_items_by_ids([8863,372362345],item_type="story')
>;
[<;hackernews.item:8863-我的yc应用程序:dropbox-扔掉你的usb驱动器>;,<;hackernews.item:-百思买骗局>;]
````
获取当前热门新闻的项目对象:
`` python
热门新闻=hn.top_stories()
注释、作业或投票:
``python
max廑item=hn.get廑max廑item()
```
max廑item
16925673
``````
再次使用"expand"标志获取面向对象的详细项表示:
``python
max廑item=hn.get廑max廑item(expand=true)
``gt;最大项目
…]
```
user.karma
155040
```
使用"expand"标志来获取用户属性的面向对象的详细项表示:
``python
user=hn.get嫒user('dhouston',expand=true)
hackernews.item:1481914-Dropbox正在招聘一名网络工程师,…]
:156692914-none>;,…]
>关于用户的工作
>关于黑客网络的工作:3955262-寻找iOS和Android工程师的下拉框,…]
``>br/>>
>要查询用户列表,请访问用户列表:
``python
users=hn.get按照用户ID(['pg'pg','dhhouston']]]]
>>python
>users=hn.get用户,按用户ID(['pg'pg','dhhouston'dhouston']]]]]]]
>>用户
>用户
>用户
[<;hackernews.user:pg>;,<;hackernews.user:dhouston>;]
````
示例
==
Get Top 10 Stories:
``python
hn.Top恛Stories(limit=10)
[<;hackernews.item:16924667-以太坊共享常见问题解答>;,<;hackernews.item:16925499-pipelinedb v0.9.9–pipelinedb是postgresql扩展之前的另一个版本>;,…]
``````
从最热门的文章中查找所有"jobs"文章:
```python
stories=hn.top\stories()
如果story.item\u type='job':
打印(故事)
·····························id=16735011
who_hilling=hn.get_item(16735011,expand=true)
for comment in who_hilling.kids:
if'python'in comment.text.lower():
print(comment)
<;hackernews.item:16735358-none>;
<;hackernews.item:16737152-none>;
———-|————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————|description default
——————————————————————————————————————————————————————————————————将所有ID转换为对象false
`get_items_by_ids`
--
description:返回"item"对象的列表
**参数:**
name键入"必需"description默认值-|————————————————————————————————————————————————————————————————————————————————————————————————注释等none
"item_type` string no item type to filter results with none
`get_user`
--
description:返回"user"对象
**参数:*
-------|false
`get_users_by_ids`
--
description:返回"user"对象的列表
**参数:*
-|——
`用户id`字符串列表/int是黑客新闻用户的唯一用户id无
`top_stories`
——
description:返回当前top stories的"item"对象列表
**参数:**
`新建新闻`
----
description:返回当前新建新闻的"item"对象列表
**参数:*
-|——————|无
`询问故事`
----
description:返回最新询问hn故事的"item"对象列表
**参数:**
`show_stories`
----
description:返回最近show hn stories的"item"对象列表
**参数:**
`作业故事`
----
description:返回最新作业故事的"item"对象列表
**参数:**
`更新`
----
说明:返回最近更改/更新的"item"和"user"对象的列表。
**参数:**
n/a
`get_max_item`
-
说明:返回当前最大项ID或当前最大项ID最大"item"对象
**参数:**
将id转换为object false
`get_all`
----
description:从hn返回所有"item"对象
**参数:**
n/a
`get_last`
----
**参数:**
|10
类:`项目`
===
项目的唯一ID。
已删除`true`如果项目已删除。
项目类型项目的类型。"作业"、"故事"、"评论"、"投票"或"投票"之一。或者,
提交时间项目的创建日期,用python"date time"表示。
文本注释、询问hn或投票文本。html.
dead `true`如果项目已死亡。
父项项目的父项。对于评论,可以是其他评论,也可以是相关报道。对于pollopt s,相关的poll。
poll poll的id。
kids项目评论的id,按显示顺序排列。
url故事的url。
score故事的得分,或pollopts的投票。
title标题故事或投票。
部分按显示顺序排列的相关投票列表。
后代在故事或投票的情况下,评论总数。
原始的json响应。
class:`user`
===
来自[官方hackernews
用户](https://github.com/hackernews/api/blob/master/readme.md-users):
-|-------------------------------------
用户ID用户的唯一用户名。区分大小写。
delay在评论创建和对其他用户可见之间的延迟(分钟)。
created用户的创建日期,用python"datetime"表示。
业力用户的业力。
关于用户的可选自我描述。html.
提交用户故事列表,投票和评论。
原始的json响应。
使用"expand"时的附加属性
属性描述
——|用户提交的评论。
作业用户提交的作业。
轮询用户提交的轮询。
轮询用户提交的轮询选项。
` requirements-dev.txt`:
==
>通过运行:
py test tests
==
有关详细信息,请检查"license"。
[![特拉维斯](https://img.shields.io/travis/avinassh/haxor.svg)](http://travis ci.org/avinassh/haxor)
[![工作服](https://img.shields.io/covertalls/avinassh/haxor.svg)](https://covertalls.io/r/avinassh/haxor?分支=主)
[![版本](https://img.shields.io/pypi/v/haxor.svg)(https://pypi.python.org/pypi/haxor/)
[![支持](https://img.shields.io/pypi/pyversions/haxor.svg)](https://pypi.python.org/pypi/haxor/)
![许可证](https://img.shieldeshields.io/pypi/l/haxor.svg)
>官方黑客新闻api的非官方的python包装器。
安装
======
`` python
pip install haxor
```
=
===
==
进口hackernews
hn=hackernews()
```
item.title
"My YC app:Dropbox-扔掉你的USB驱动器"
"item.item"type
"story"
"item.kids"
"[8952、9224、8917,…]
"```
",因为大多数结果都返回为整数ID(如上面的item.kids),这些结果需要进一步迭代。不要自己这样做,而是使用"expand"标志按ID获取面向对象的详细项目信息:
``python
item=hn.get\item(8863,expand=true)
项目。通过
\lt;hackernews.user:dhouston>;
````
>查询项目ID列表:
```python
````````````````````
``items=hn。通过项目ID([8863,37236,2345])
>项目。通过项目ID([8863,37236,2345,37236,2345;[8863,37236,2345])
>>项目
>>>>>项目
===>>>[<;黑客。项目:8863;hackernews.item:8863-我的yc app:dropbox:dr.项目:
#37236-none>;,<;hackernews.item:2345-百思买骗局。>;]
````
使用"item_type"筛选器具体选择"story"、"comment"、"job"或"poll"项:
``python
items=hn.get_items_by_ids([8863,372362345],item_type="story')
>;
[<;hackernews.item:8863-我的yc应用程序:dropbox-扔掉你的usb驱动器>;,<;hackernews.item:-百思买骗局>;]
````
获取当前热门新闻的项目对象:
`` python
热门新闻=hn.top_stories()
注释、作业或投票:
``python
max廑item=hn.get廑max廑item()
```
max廑item
16925673
``````
再次使用"expand"标志获取面向对象的详细项表示:
``python
max廑item=hn.get廑max廑item(expand=true)
``gt;最大项目
…]
```
user.karma
155040
```
使用"expand"标志来获取用户属性的面向对象的详细项表示:
``python
user=hn.get嫒user('dhouston',expand=true)
hackernews.item:1481914-Dropbox正在招聘一名网络工程师,…]
:156692914-none>;,…]
>关于用户的工作
>关于黑客网络的工作:3955262-寻找iOS和Android工程师的下拉框,…]
``>br/>>
>要查询用户列表,请访问用户列表:
``python
users=hn.get按照用户ID(['pg'pg','dhhouston']]]]
>>python
>users=hn.get用户,按用户ID(['pg'pg','dhhouston'dhouston']]]]]]]
>>用户
>用户
>用户
[<;hackernews.user:pg>;,<;hackernews.user:dhouston>;]
````
示例
==
Get Top 10 Stories:
``python
hn.Top恛Stories(limit=10)
[<;hackernews.item:16924667-以太坊共享常见问题解答>;,<;hackernews.item:16925499-pipelinedb v0.9.9–pipelinedb是postgresql扩展之前的另一个版本>;,…]
``````
从最热门的文章中查找所有"jobs"文章:
```python
stories=hn.top\stories()
如果story.item\u type='job':
打印(故事)
·····························id=16735011
who_hilling=hn.get_item(16735011,expand=true)
for comment in who_hilling.kids:
if'python'in comment.text.lower():
print(comment)
<;hackernews.item:16735358-none>;
<;hackernews.item:16737152-none>;
———-|————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————|description default
——————————————————————————————————————————————————————————————————将所有ID转换为对象false
`get_items_by_ids`
--
description:返回"item"对象的列表
**参数:**
name键入"必需"description默认值-|————————————————————————————————————————————————————————————————————————————————————————————————注释等none
"item_type` string no item type to filter results with none
`get_user`
--
description:返回"user"对象
**参数:*
`get_users_by_ids`
--
description:返回"user"对象的列表
**参数:*
-|——
`用户id`字符串列表/int是黑客新闻用户的唯一用户id无
`top_stories`
——
description:返回当前top stories的"item"对象列表
**参数:**
`新建新闻`
----
description:返回当前新建新闻的"item"对象列表
**参数:*
-|——————|无
`询问故事`
----
description:返回最新询问hn故事的"item"对象列表
**参数:**
`show_stories`
----
description:返回最近show hn stories的"item"对象列表
**参数:**
`作业故事`
----
description:返回最新作业故事的"item"对象列表
**参数:**
`更新`
----
说明:返回最近更改/更新的"item"和"user"对象的列表。
**参数:**
n/a
`get_max_item`
-
说明:返回当前最大项ID或当前最大项ID最大"item"对象
**参数:**
将id转换为object false
`get_all`
----
description:从hn返回所有"item"对象
**参数:**
n/a
`get_last`
----
**参数:**
|10
类:`项目`
===
项目的唯一ID。
已删除`true`如果项目已删除。
项目类型项目的类型。"作业"、"故事"、"评论"、"投票"或"投票"之一。或者,
提交时间项目的创建日期,用python"date time"表示。
文本注释、询问hn或投票文本。html.
dead `true`如果项目已死亡。
父项项目的父项。对于评论,可以是其他评论,也可以是相关报道。对于pollopt s,相关的poll。
poll poll的id。
kids项目评论的id,按显示顺序排列。
url故事的url。
score故事的得分,或pollopts的投票。
title标题故事或投票。
部分按显示顺序排列的相关投票列表。
后代在故事或投票的情况下,评论总数。
原始的json响应。
class:`user`
===
来自[官方hackernews
用户](https://github.com/hackernews/api/blob/master/readme.md-users):
-|-------------------------------------
用户ID用户的唯一用户名。区分大小写。
delay在评论创建和对其他用户可见之间的延迟(分钟)。
created用户的创建日期,用python"datetime"表示。
业力用户的业力。
关于用户的可选自我描述。html.
提交用户故事列表,投票和评论。
原始的json响应。
使用"expand"时的附加属性
属性描述
——|用户提交的评论。
作业用户提交的作业。
轮询用户提交的轮询。
轮询用户提交的轮询选项。
` requirements-dev.txt`:
>通过运行:
有关详细信息,请检查"license"。