Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active February 29, 2016 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/e2aaf128c6ef49704575 to your computer and use it in GitHub Desktop.
Save kurozumi/e2aaf128c6ef49704575 to your computer and use it in GitHub Desktop.
【Python】標準入力したURLのはてなブックマークの合計数を標準出力する方法
# 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