F#でTwitter
.NET Frameworkがあるから簡単!
タイムラインを表示するだけの簡単なプログラムです。
#light open System open System.Net open System.Xml let userName = "nobuhisa_k" let pass = "ひみつ☆" let uri = "http://twitter.com/statuses/friends_timeline.xml?count=10" //最高で200 let getStream () : IO.Stream = let req = WebRequest.Create uri :?> HttpWebRequest req.Credentials <- new NetworkCredential ( userName, pass ) let res = req.GetResponse () :?> HttpWebResponse res.GetResponseStream () let getStatuses () : XmlNodeList = let stream = getStream () let document = new Xml.XmlDocument () document.Load stream stream.Close () document.SelectNodes "/statuses/status" let getText (node:XmlNode) (name:string) : string = let text = node.SelectSingleNode name in text.InnerText let build (node:XmlNode) : string = let user = getText (node.SelectSingleNode "user") user "screen_name" + " @ " + user "location" + " :\n" + getText node "text" let _ = let timeLine = getStatuses () timeLine |> Seq.cast<XmlNode> |> Seq.map build |> Seq.iter (fun x -> printfn "%s\n" x |> ignore) stdout.WriteLine( "おしまい" )
なんか上手く書けないなぁ。まあただの練習不足なんですが。
リファクタリング/へんな部分の指摘歓迎です><