Skip to content

Instantly share code, notes, and snippets.

@jboner
Forked from Villane/ReTweetRec.scala
Created July 17, 2009 22:26
Show Gist options
  • Save jboner/149315 to your computer and use it in GitHub Desktop.
Save jboner/149315 to your computer and use it in GitHub Desktop.
ReTweetRec
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 = "debasishg"
val user2 = "jboner"
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 rec = sameSize.toFloat/diffSize > 1f/3
println("Recommendation: " + (if(rec) "don't retweet!" else "retweet!"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment