Last active
February 29, 2016 11:14
-
-
Save kurozumi/e2aaf128c6ef49704575 to your computer and use it in GitHub Desktop.
【Python】標準入力した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
# coding: utf-8 | |
import urllib | |
import xmlrpclib | |
while True: | |
# 標準入力の値を取得 | |
uri = raw_input() | |
# urlをパース | |
type, uri = urllib.splittype(uri) | |
# urlのスキームをチェック | |
if type not in ("http", "https"): | |
raise IOError("unsupported protocol") | |
server = xmlrpclib.ServerProxy("http://b.hatena.ne.jp/xmlrpc") | |
# はてブの合計数を出力 | |
print server.bookmark.getTotalCount(type + ":" + uri) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment