-
-
Save jboner/149315 to your computer and use it in GitHub Desktop.
ReTweetRec
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
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