import twitter4j.*; import twitter4j.auth.AccessToken; import java.util.List; import java.util.ArrayList; import java.text.DateFormat; import java.text.SimpleDateFormat; public class SearchTweets { private static ArrayList carros = new ArrayList(); private static List tweets = null; private static int i; private static ArrayList td = new ArrayList (); public SearchTweets(String fecha){ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer("jNv4aV6EPmhpvLjbom2PjXvCw", "yUbNYP1kXJYVscP021Mds0uZqdxgU0LdqP3H5W4lCxpGWRXMQ3"); twitter.setOAuthAccessToken(new AccessToken("741853864714997760-gVz5r1epXTBmjlJvmMyZO09EdgKmYey","YA8FNiKyCsqBhrUV5tTowloAOY5FySKL5uLmmOg2OHvIG")); int h = 0; try { Query query = new Query("zeus_talca"); query.setCount(100); QueryResult result; i = 0; result = twitter.search(query); tweets = result.getTweets(); for (Status tweet : tweets) { h++; if (fecha.equals(dateFormat.format(tweet.getCreatedAt()))){ String s = tweet.getText(); String ss = tweet.getText()+" "+dateFormat.format(tweet.getCreatedAt()); if (i==0) td.add(0, ss); String g[] = s.split(" : |\\, | "); if (i==1){ int c = g.length - 1; for (int x = 1; x < c;x++){ if (g[0].equals("0-9")){ Carro carrA = new Carro(g[x], g[0], "En Servicio", g[c],dateFormat.format(tweet.getCreatedAt()) ); carros.add(carrA); } } for (int x = 2; x < c;x++){ if (g[0].equals("0-8") && g[1].equals("Disponible")){ Carro carrB = new Carro(g[x], g[0], g[1], g[c],dateFormat.format(tweet.getCreatedAt())); carros.add(carrB); } } for (int x = 3; x < c;x++){ if (g[0].equals("0-8") && g[1].equals("En") && g[2].equals("Taller")){ Carro carrC = new Carro(g[x], g[0], g[1]+" "+g[2], g[c],dateFormat.format(tweet.getCreatedAt())); carros.add(carrC); } } } if (g[0].equals("Boletin")){ i++;} } if (i==2) break; } System.out.println(h); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); } } public ArrayList GetCarros(){ return carros; } public void printCarros(){ System.out.println("---------------------------------------------------"); for (Carro y : carros){ y.getDetalles(); } } public boolean carroEmpty(){ return carros.isEmpty(); } public List getLista(){ return tweets; } public ArrayList gettd(){ return td; } }