-->

Saturday, 21 April 2012

Beccome A Stealth Mountain Acolyte

According to Buzzfeed, Stealth Mountain is the Twitter account that is doing God's work. It is simply an account that finds people on Twitter using the phrase "sneak peak" and then tweets at them, "I think you meant 'sneak peak'". That is all he tweets; the timeline is a continuous stream of that one phrase aimed at different users. The humour in the account is how people react to it. Expletive-laden responses encourage the tweeter to get a life. It must take a lot of patience from a very lonely person to run such an account. Or does it?



Also doing God's work



The following code replicates what stealth mountain does. I am sure Twitter has some spam limit but, in theory, you could tweet at every user who made this mistake - about five users per minute in my limited sampling.  The code works by searching for all recent tweets with "sneak peak" in them. It then checks the follower count of the user who made each tweet. It then tweets at the tweeter with the greatest follower count.

Obviously, I am thinking of creating an app so you can join in the fun.


public class StealthMountain {
 
 final private Twitter twitter;
 final private Query sneakPeakQuery;

 private StealthMountain(final Twitter twitter, final Query query){
  this.twitter = twitter;
  this.sneakPeakQuery = query;
 }

 
 public static void main(String[] args) throws TwitterException {
  String consumerKey = "";
  String consumerSecret = "";
  
  ConfigurationBuilder cb = new ConfigurationBuilder();
  cb.setDebugEnabled(true)
    .setOAuthConsumerKey(consumerKey)
    .setOAuthConsumerSecret(consumerSecret)
    .setOAuthAccessToken("")
    .setOAuthAccessTokenSecret("");
  
  
  
  Twitter twitter = new TwitterFactory(cb.build()).getInstance();
     
     StealthMountain mountain = StealthMountain.createStealthMountain(twitter);
     mountain.attack();

 }

 private void attack() throws TwitterException {
  User mostPopularUser = mostPopularUserFrom(getRecentTweets()); 
  sendMessageInResponseToTweet(mostPopularUser);
 }

 private void sendMessageInResponseToTweet(User user) throws TwitterException {
  twitter.updateStatus("@" + user.getScreenName() + "I think you mean \"sneak peek\"");
 }

 
 
 private User mostPopularUserFrom(List recentTweets) throws TwitterException {
  
  
  User mostPopularUserSoFar = userFrom(recentTweets.get(0));
  
  int mostPopularUserSoFarFollerCount = mostPopularUserSoFar.getFollowersCount();
  
  for (Tweet newTweet : recentTweets) {
      if (getFollowerCountFromTweet(newTweet) > mostPopularUserSoFarFollerCount ){
       mostPopularUserSoFar = userFrom(newTweet);
       mostPopularUserSoFarFollerCount = mostPopularUserSoFar.getFollowersCount();
      }
         
     }
  
  return mostPopularUserSoFar;
 }

 private User userFrom(Tweet tweet) throws TwitterException {
  
  return twitter.showUser(tweet.getFromUser());
 }

 private int getFollowerCountFromTweet(Tweet tweet) throws TwitterException {
  return twitter.showUser(tweet.getFromUser()).getFollowersCount();
 }

 private List getRecentTweets() throws TwitterException {
  return twitter.search(sneakPeakQuery).getTweets();
  
  
 }

 private static StealthMountain createStealthMountain(Twitter twitter) {
  Query query = new Query("sneak peak");
  query.setSince(new LocalDate().minusDays(1).toString());
  query.setResultType(Query.RECENT);
     
  
  return new StealthMountain(twitter, query);
 }

}

Arrow Key Nav