Skip to content

Instantly share code, notes, and snippets.

@Villane
Created July 17, 2009 22:06
Show Gist options
  • Save Villane/149304 to your computer and use it in GitHub Desktop.
Save Villane/149304 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