Created
October 23, 2009 12:24
-
-
Save yuroyoro/216843 to your computer and use it in GitHub Desktop.
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
import scala.xml._ | |
import scala.io.Source | |
object LDRFeedSummary { | |
val opmlUrl = "http://reader.livedoor.com/user/%s/opml" | |
val r = """http\:\/\/([^\/]+)\/.*$""".r | |
// まとめるドメイン | |
val topLevelDomain = List("fc2.com", | |
"blogspot.com", | |
"g.hatena.ne.jp", | |
"tumblr.com", | |
"exblog.jp", | |
"justblog.jp", | |
"blog.so-net.ne.jp", | |
"ameba.jp", | |
"sakura.ne.jp", | |
"seesaa.net", | |
"cocolog-nifty.com") | |
def getDomain( domain:String) = | |
topLevelDomain.find( domain.endsWith( _ )).getOrElse( domain ) | |
def main( args:Array[String] ) = { | |
val url = opmlUrl.format( args.first ) | |
val source = Source.fromURL( url ) | |
val xml = XML.loadString( source.getLines.mkString )// XML取得 | |
val feeds = xml \ "body" \ "outline" \ "outline" \ "outline" | |
val totalCount:Double = feeds.size | |
(Map.empty[String, Int]/: feeds)( | |
(m:Map[String, Int] , feed:NodeSeq) => { | |
(feed \ "@xmlUrl" text ) match { | |
case r( domain ) => | |
val d = getDomain( domain ) | |
m + ( d -> (m.getOrElse( d , 0) + 1 )) | |
case _ => m | |
} | |
} | |
).toList.partition{ | |
case (k, v)=> v > 1 | |
} match { | |
case (l1, l2 ) => | |
l1.sort{ | |
case ((k1, v1), (k2, v2)) => v1 > v2 | |
}.foreach{ | |
case (k, v) => | |
println( "%-30s : %3d ( %2.2f )".format( k, v , (v / totalCount * 100) )) | |
} | |
println( "%-30s : %3d ( %2.2f )".format( "Other", l2.size , (l2.size / totalCount * 100) )) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment