Skip to content

Commit

Permalink
fix comments order bug
Browse files Browse the repository at this point in the history
  • Loading branch information
laike9m committed Mar 19, 2016
1 parent 16b36b8 commit b4ab39a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dynamic/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def execute(self):
'cid': comment.cid
}
if new_commenters:
new_commenters = list(reversed(new_commenters.values()))
new_commenters = list(new_commenters.values())
new_commenters.sort(key=lambda x: x['time'])

# add collectors
# 收藏夹不是按时间返回, 所以只能全部扫一遍
Expand Down
24 changes: 24 additions & 0 deletions test_zhihu-py3/test_fetch_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from client import client
from zhihu import ANONYMOUS
from pprint import pprint


answer = client.answer('https://www.zhihu.com/question/40601601/answer/87377293')
# for comment in answer.latest_comments:
# print(comment.author.id)

new_commenters = {}
for comment in answer.latest_comments:
if comment.author is ANONYMOUS:
continue
else:
new_commenters[comment.author.id] = {
'uid': comment.author.id,
'time': comment.creation_time,
'cid': comment.cid
}
if new_commenters:
new_commenters = list(new_commenters.values())
new_commenters.sort(key=lambda x: x['time'])

pprint(new_commenters)

0 comments on commit b4ab39a

Please sign in to comment.