Skip to content

Instantly share code, notes, and snippets.

@fogus
Forked from Villane/ReTweetRec.scala
Created July 18, 2009 02:35
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 fogus/149383 to your computer and use it in GitHub Desktop.
Save fogus/149383 to your computer and use it in GitHub Desktop.
package retweetrec
import scala.xml.XML
import java.net.URL
import java.io.InputStream
object ReTweetRec {
def getFollowers(id: String) = {
val data = new URL("http://twitter.com/followers/ids/" + id + ".xml").getContent
val xml = XML.load(data.asInstanceOf[InputStream])
for (id <- xml \ "id") yield id.text
}
def main(args : Array[String]) : Unit = {
val user1 = args(0)
val user2 = args(1)
val followers1 = getFollowers(user1)
val followers2 = getFollowers(user2)
val (same, diff) = followers1.partition(followers2.contains)
val sameSize = same.toList.size
val diffSize = diff.toList.size
println("Followers of both " + user1 + " and " + user2 + ": " + sameSize)
println("Followers of " + user1 + " not following " + user2 + ": " + diffSize)
val percentSame = sameSize / followers1.size.toFloat
println("Percentage of shared followers %.1f%%".format(percentSame * 100))
println("Recommendation: " + (if (percentSame > 1/3f) "don't retweet!" else "retweet!"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment