最近投稿したはてなブックマークの一覧を取得するスクリプト
さっき作ったWSSE認証用のスクリプトを使って、はてなブックマークから最近投稿したブクマ一覧を取得するスクリプトを作った。
Get-RecentBookmark.ps1
param([string]$userName, [string]$password) if($userName.Length -eq 0 -or $password.Length -eq 0 -or $args[0] -eq "-?") { $commandName = [IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name) Write-Host -foregroundColor Yellow @" Name: $commandName Description: はてなブックマークから最近投稿したブックマークの一覧を取得します。 Usage: $commandName [[-userName] <string>] [[-password] <string>] -userName <string> ユーザ名 -password <string> パスワード "@ exit 1 } $webReq = [Net.HttpWebRequest]::Create("http://b.hatena.ne.jp/atom/feed") $webReq.Headers.Add("X-WSSE", (Get-WsseHeader $userName $password)) $webReq.ContentType = "application/xatom+xml, application/xml, text/xml, */*" $webReq.Method = "GET" $webRes = $webReq.GetResponse() $sr = New-Object IO.StreamReader($webRes.GetResponseStream()) $result = [xml]$sr.ReadToEnd() $sr.Close() $webRes.Close() $result.feed.entry
使い方
PS > Get-RecentBookmark ユーザ名 パスワード title : ZoomIt link : {link, link, link} issued : 2008-03-27T22:56:41+09:00 author : author id : tag:hatena.ne.jp,2005:bookmark-coma2n-8032703 summary : summary subject : 便利ツール title : Silverlight 2 Betaのコントロールテンプレートモデルに関する是非 - Yuya Yamaki’s blog link : {link, link, link} issued : 2008-03-27T19:15:57+09:00 author : author id : tag:hatena.ne.jp,2005:bookmark-coma2n-8030554 summary : summary subject : {.NET, Silverlight, WPF} title : jQuery File Tree link : {link, link, link} issued : 2008-03-27T13:18:14+09:00 author : author id : tag:hatena.ne.jp,2005:bookmark-coma2n-8024680 summary : summary subject : {JavaScript, jQuery}
出力される情報はだいぶ適当。XmlNodeのままなので取得する側で調整する必要あり。