Created
February 6, 2016 12:43
-
-
Save gh640/e1fa3b8c327214569f81 to your computer and use it in GitHub Desktop.
特定のサイトやページのはてブ数を取得するターミナル関数
This file contains hidden or 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
| # サイト全体のはてブ数を取得する | |
| # get the sum total of hatena bookmark count for a site | |
| # | |
| # usage: | |
| # hatena_get_count_for_site http://example.com | |
| # | |
| function hatena_get_count_for_site { | |
| # @see http://developer.hatena.ne.jp/ja/documents/bookmark/apis/getcount | |
| if [ "$#" -ne 1 ]; then | |
| echo 'usage: get_hatena_count_for_site [url]' | |
| return | |
| fi | |
| xmlheader="Content-Type: text/xml" | |
| xmldata="<methodCall><methodName>bookmark.getTotalCount</methodName><params><param><value><string>${1}</string></value></param></params></methodCall>" | |
| xmlurl="http://b.hatena.ne.jp/xmlrpc" | |
| curl -s -H $xmlheader -d $xmldata $xmlurl | | |
| grep -oE "<int>\d+?</int>" | | |
| grep -oE "\d+" | |
| } | |
| # 特定のページのはてブ数を取得する | |
| # get hatena bookmark count for a url | |
| # | |
| # usage: | |
| # hatena_get_count http://example.com/about | |
| # | |
| function hatena_get_count { | |
| # @see http://developer.hatena.ne.jp/ja/documents/bookmark/apis/getcount | |
| if [ "$#" -ne 1 ]; then | |
| echo 'usage: get_hatena_count [url]' | |
| return | |
| fi | |
| geturl="http://api.b.st-hatena.com/entry.count?url=${1}" | |
| curl -s $geturl | |
| echo "" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment