Last active
July 22, 2021 16:14
-
-
Save ayu-mushi/39fe10d9cd78a57f91d424c64811319e to your computer and use it in GitHub Desktop.
URLを受けとってはてなブックマークの情報を返す
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
#!/usr/bin/env python2 | |
# -*- coding: utf-8- -*- | |
# URLを受けとってはてなブックマークの情報を返す | |
import urllib2 | |
import argparse | |
import json | |
def bukome(args): | |
req = urllib2.Request('http://b.hatena.ne.jp/entry/json/' + args.uri); | |
response = urllib2.urlopen(req) | |
json_hate = response.read() | |
parsed_hate = json.loads(json_hate) | |
print "-----" | |
print "count:" + str(parsed_hate["count"]) | |
print "comments: \n" + reduce(lambda comm0, comm1: comm0 if comm1 == "" else comm0 + "\n\n[ " + comm1 + " ]", map(lambda bkm: bkm["comment"], parsed_hate["bookmarks"]), "") | |
parser = argparse.ArgumentParser(description='print bookmark comments in hatena.ne.jp') | |
parser.add_argument('uri', type=str, help='the URI of the target web page') | |
parser.set_defaults(func=bukome) | |
args = parser.parse_args() | |
args.func(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
憎悪情報みたいになってる