private void grabTrending() { try { if (VERBOSE) { DAO.log("Kaizen is going to get trending topics ..."); } for (Location location : twitter.trends().getAvailableTrends()) { for (Trend trend : twitter.trends().getPlaceTrends(location.getWoeid()).getTrends()) { this.queries.addQuery(trend.getQuery()); } } } catch (TwitterException e) { if (e.getErrorCode() != 88) { DAO.severe(e); } } }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Trends)) return false; Trends trends1 = (Trends) o; if (asOf != null ? !asOf.equals(trends1.getAsOf()) : trends1.getAsOf() != null) return false; if (trendAt != null ? !trendAt.equals(trends1.getTrendAt()) : trends1.getTrendAt() != null) return false; if (!Arrays.equals(trends, trends1.getTrends())) return false; return true; }
@Converter public static String toString(Trends trends) throws ParseException { StringBuilder s = new StringBuilder(); s.append("(" + trends.getTrendAt().toString() + ") "); boolean first = true; for (Trend trend : trends.getTrends()) { if (first) { first = false; } else { s.append(","); } s.append(toString(trend)); } return s.toString(); }
for (Trends trends : dailyTrends) { System.out.println("As of : " + trends.getAsOf()); System.out.println(" " + trends.getTrendAt()); }
List<Trends> trends; try { Date asOf = parseDate(json.getString("as_of")); JSONObject trendsJson = json.getJSONObject("trends"); trends = new ArrayList<Trends>(trendsJson.length()); String key = (String) ite.next(); JSONArray array = trendsJson.getJSONArray(key); Trend[] trendsArray = jsonArrayToTrendArray(array); if (key.length() == 19) { trends.add(new Trends(res, asOf, parseDate(key , "yyyy-MM-dd HH:mm:ss"), trendsArray)); } else if (key.length() == 16) { trends.add(new Trends(res, asOf, parseDate(key , "yyyy-MM-dd HH:mm"), trendsArray)); } else if (key.length() == 10) { trends.add(new Trends(res, asOf, parseDate(key , "yyyy-MM-dd"), trendsArray));
@Override public int compareTo(Trends that) { return this.trendAt.compareTo(that.getTrendAt()); }
/** * Returns the current top 10 trending topics on Twitter. The response includes the time of the request, the name of each trending topic, and query used on <a href="http://search.twitter.com/">Twitter Search</a> results page for that topic. * <br>This method calls http://search.twitter.com/trends/current * @return the result * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.2 * @see <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-trends">Twitter Search API Method: trends</a> */ public Trends getCurrentTrends() throws TwitterException { return Trends.constructTrendsList(get(searchBaseURL + "trends/current.json" , false)).get(0); }
/** * Returns the top ten topics that are currently trending on Twitter. The response includes the time of the request, the name of each trend, and the url to the <a href="http://search.twitter.com/">Twitter Search</a> results page for that topic. * <br>This method calls http://search.twitter.com/trends * @return the result * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.2 * @see <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-trends">Twitter Search API Method: trends</a> */ public Trends getTrends() throws TwitterException { return Trends.constructTrends(get(searchBaseURL + "trends.json", false)); }
static Trends constructTrends(Response res) throws TwitterException { JSONObject json = res.asJSONObject(); try { Date asOf = parseDate(json.getString("as_of")); JSONArray array = json.getJSONArray("trends"); Trend[] trendsArray = jsonArrayToTrendArray(array); return new Trends(res, asOf, asOf, trendsArray); } catch (JSONException jsone) { throw new TwitterException(jsone.getMessage() + ":" + res.asString(), jsone); } }
/** * Returns the top 30 trending topics for each day in a given week. * <br>This method calls http://search.twitter.com/trends/weekly * @return the result * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.2 * @see <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-trends-weekly">Twitter Search API Method: trends weekly</a> */ public List<Trends> getWeeklyTrends() throws TwitterException { return Trends.constructTrendsList(get(searchBaseURL + "trends/weekly.json", false)); }
/** * Returns the top 20 trending topics for each hour in a given day. * <br>This method calls http://search.twitter.com/trends/daily * @return the result * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.2 * @see <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-trends-daily">Twitter Search API Method: trends daily</a> */ public List<Trends> getDailyTrends() throws TwitterException { return Trends.constructTrendsList(get(searchBaseURL + "trends/daily.json", false)); }
/** * Returns the current top 10 trending topics on Twitter. The response includes the time of the request, the name of each trending topic, and query used on <a href="http://search.twitter.com/">Twitter Search</a> results page for that topic. * <br>This method calls http://search.twitter.com/trends/current * @param excludeHashTags Setting this to true will remove all hashtags from the trends list. * @return the result * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.2 * @see <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-trends">Twitter Search API Method: trends</a> */ public Trends getCurrentTrends(boolean excludeHashTags) throws TwitterException { return Trends.constructTrendsList(get(searchBaseURL + "trends/current.json" + (excludeHashTags ? "?exclude=hashtags" : ""), false)).get(0); }
/** * Returns the top 20 trending topics for each hour in a given day. * <br>This method calls http://search.twitter.com/trends/daily * @param date Permits specifying a start date for the report. * @param excludeHashTags Setting this to true will remove all hashtags from the trends list. * @return the result * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.2 * @see <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-trends-daily">Twitter Search API Method: trends daily</a> */ public List<Trends> getDailyTrends(Date date, boolean excludeHashTags) throws TwitterException { return Trends.constructTrendsList(get(searchBaseURL + "trends/daily.json?date=" + toDateStr(date) + (excludeHashTags ? "&exclude=hashtags" : ""), false)); }
/** * Returns the top 30 trending topics for each day in a given week. * <br>This method calls http://search.twitter.com/trends/weekly * @param date Permits specifying a start date for the report. * @param excludeHashTags Setting this to true will remove all hashtags from the trends list. * @return the result * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.2 * @see <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-trends-weekly">Twitter Search API Method: trends weekly</a> */ public List<Trends> getWeeklyTrends(Date date, boolean excludeHashTags) throws TwitterException { return Trends.constructTrendsList(get(searchBaseURL + "trends/weekly.json?date=" + toDateStr(date) + (excludeHashTags ? "&exclude=hashtags" : ""), false)); }