Last active
March 5, 2017 11:03
-
-
Save OwenChia/eef50a3fcc6076e2f6867d659a6f343a to your computer and use it in GitHub Desktop.
Get the unique repliy list from v2ex.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from functools import reduce | |
from urllib import request | |
import argparse | |
import json | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument("topic", type=int, nargs='?', default=293899) | |
args = parser.parse_args() | |
API_REPLIES = r"http://www.v2ex.com/api/replies/show.json?topic_id={}".format | |
def uniq_replies(topic_id): | |
with request.urlopen(API_REPLIES(topic_id)) as httpfd: | |
response = httpfd.read() | |
result = json.loads(response.decode()) | |
replies = (x['member']['username'] for x in result) | |
uniq_lst = reduce(lambda x, y: x if y in x else x + [y], replies, []) | |
return enumerate(uniq_lst) | |
if __name__ == '__main__': | |
for each in uniq_replies(args.topic): | |
print(each) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment