TwitterGroovy
import java.util.List; import twitter4j.Twitter; import org.w3c.dom.Document; import java.util.Date; import java.text.*;
public class TwitterGroovy { Twitter twitter;
public Twitter getTwitter(twitterID, twitterPassword) { if (twitter!=null) return twitter; twitter = new Twitter(twitterID,twitterPassword); return twitter; }
public List search(String text) { String url = "http://search.twitter.com/search.atom?q=" + text; def resp = twitter.get(url, true); def xml = resp.asString(); def list = new ArrayList(); def node = new XmlSlurper().parseText(xml) for (entry in node.entry) { String authoruri = entry.author.uri; String authorid = authoruri.substring(authoruri.lastIndexOf("/") + 1); Date publishDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ").parse(entry.published); def user = [ "id" : authorid, "name" : entry.author.name, "screenName" : authorid, "location" : "", "description" : "", "profileImageUrl": "", "url" : authoruri, "isProtected" : "", "followersCount" : -1]; def st = content, "source" : "", "isTruncated" : false, "inReplyToStatusId": "", "inReplyToUserId": "", "user" : user; list.add(st); } return list; } }