Example usage for twitter4j Trend getName

List of usage examples for twitter4j Trend getName

Introduction

In this page you can find the example usage for twitter4j Trend getName.

Prototype

String getName();

Source Link

Usage

From source file:com.twitstreet.twitter.TwitterProxyImpl.java

License:Open Source License

@Override
public Set<String> getTrends() {
    Set<String> trendSet = new HashSet<String>();

    int i = 0;//from ww  w.j a  v  a2 s. c  o m
    for (String location : woiedMap.keySet()) {

        if (i > 0 && configMgr.isDev()) {

            break;
        }

        int woied = woiedMap.get(location);
        try {
            Trends ts = twitter.getLocationTrends(woied);
            if (ts != null) {
                Trend[] trends = ts.getTrends();
                if (trends != null) {
                    logger.debug("Location: " + location + ", trend size: " + trends.length);
                    for (Trend trend : trends) {
                        trendSet.add(trend.getName());
                    }
                }
            }
        } catch (TwitterException e) {
            e.printStackTrace();
        }

        i++;
    }
    return trendSet;
}

From source file:DataCollections.HashTagHelper.java

public void insertTrends(Trend[] trends) {
    boolean[] selection = new boolean[Hashtag_dbo.nooffields];
    Hashtag_dbo hashtag;/*from   ww  w.  ja  va  2 s .  com*/

    for (Trend t : trends) {
        LogPrinter.printLog("Processing a trend" + t.getName());

        if (HashTagTable.select("hashtag_popterm = \"" + t.getName() + "\"", 0, 1).length == 0) {
            hashtag = convertTrendToHashTag_dbo(t);
            for (int j = 0; j < Hashtag_dbo.nooffields; j++) {
                selection[j] = hashtag.values[j].used;
            }
            HashTagTable.insert(hashtag, selection);
            LogPrinter.printLog(selection.toString());
        }
    }
}

From source file:DataCollections.HashTagHelper.java

public Hashtag_dbo convertTrendToHashTag_dbo(Trend trend) {
    Hashtag_dbo hashtag = new Hashtag_dbo();
    Logger.LogPrinter.printLog("Converting Trend " + trend.getName() + " to HashTag_dbo");
    hashtag.values[Hashtag_dbo.map.get("hashtag_popterm")].setValue(trend.getName());
    hashtag.values[Hashtag_dbo.map.get("ftrendsres")].setValue("true");
    return hashtag;
}

From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java

License:Open Source License

public static ContentValues[] makeTrendsContentValues(final List<Trends> trendsList) {
    if (trendsList == null)
        return new ContentValues[0];
    final List<ContentValues> resultList = new ArrayList<>();
    for (final Trends trends : trendsList) {
        if (trends == null) {
            continue;
        }//  ww w.ja  v a 2s .  c o m
        final long timestamp = trends.getTrendAt().getTime();
        for (final Trend trend : trends.getTrends()) {
            final ContentValues values = new ContentValues();
            values.put(CachedTrends.NAME, trend.getName());
            values.put(CachedTrends.TIMESTAMP, timestamp);
            resultList.add(values);
        }
    }
    return resultList.toArray(new ContentValues[resultList.size()]);
}

From source file:org.apache.camel.component.twitter.util.TwitterConverter.java

License:Apache License

@Converter
public static String toString(Trend trend) throws ParseException {
    return trend.getName();
}

From source file:org.getlantern.firetweet.util.ContentValuesCreator.java

License:Open Source License

public static ContentValues[] createTrends(final List<Trends> trendsList) {
    if (trendsList == null)
        return new ContentValues[0];
    final List<ContentValues> resultList = new ArrayList<>();
    for (final Trends trends : trendsList) {
        final long timestamp = trends.getTrendAt().getTime();
        for (final Trend trend : trends.getTrends()) {
            final ContentValues values = new ContentValues();
            values.put(CachedTrends.NAME, trend.getName());
            values.put(CachedTrends.TIMESTAMP, timestamp);
            resultList.add(values);/*from   www  .  j a  v  a  2  s  .c om*/
        }
    }
    return resultList.toArray(new ContentValues[resultList.size()]);
}

From source file:org.jwebsocket.plugins.twitter.TwitterPlugIn.java

License:Apache License

private void getTrends(WebSocketConnector aConnector, Token aToken) {
    TokenServer lServer = getServer();//from  w  w  w  .  j  a va 2s .  co  m

    // instantiate response token
    Token lResponse = lServer.createResponse(aToken);
    String lMsg;

    try {
        if (mLog.isDebugEnabled()) {
            mLog.debug("Retreiving trends...");
        }
        if (!mCheckAuth(lResponse)) {
            mLog.error(lResponse.getString("msg"));
        } else {
            // return the list of messages as an array of strings...
            Map<String, List<String>> lAsOf = new FastMap<String, List<String>>();
            List<String> lMessages;
            ResponseList lTrendList = mTwitter.getDailyTrends();
            for (int lIdx = 0; lIdx < lTrendList.size(); lIdx++) {
                lMessages = new FastList<String>();
                Trends lTrends = (Trends) lTrendList.get(lIdx);
                Trend[] lTrendArray = lTrends.getTrends();
                for (Trend lTrend : lTrendArray) {
                    lMessages.add(lTrend.getName() + ": " + lTrend.getQuery() + ", URL: " + lTrend.getUrl());
                }
                lAsOf.put(Tools.DateToISO8601(lTrends.getTrendAt()), lMessages);
            }
            lResponse.setMap("messages", lAsOf);
            if (mLog.isInfoEnabled()) {
                mLog.info("Trends successfully received");
            }
        }
    } catch (Exception lEx) {
        lMsg = lEx.getClass().getSimpleName() + ": " + lEx.getMessage();
        mLog.error(lMsg);
        lResponse.setInteger("code", -1);
        lResponse.setString("msg", lMsg);
    }

    // send response to requester
    lServer.sendToken(aConnector, lResponse);
}

From source file:project.mum.TwitterTrend.java

public List getTrends(double longi, double lati) throws TwitterException {
    List availableTrends = new ArrayList<String>();

    ConfigurationBuilder cf = new ConfigurationBuilder();
    cf.setDebugEnabled(true).setOAuthConsumerKey("TBFU8jBXiIOEde0cnSglw2m7B")
            .setOAuthConsumerSecret("c0tJVVvGgpY2rI1Ol5qmxzMpB1MiBx8PGlLNPG7TYAAVXwYVvL")
            .setOAuthAccessToken("1148852892-OR8mM62nOH4WPJf991X5bCp4zVKT2EU57fBmjWQ")
            .setOAuthAccessTokenSecret("zpXLqUxlkHZT58RDbGEPLnXVB3Kpwp7d8Z4CKb4X4UJW6");
    TwitterFactory tf = new TwitterFactory(cf.build());
    twitter4j.Twitter twitter = tf.getInstance();
    ResponseList<Location> locations;
    List<MyTrend> myTrend = new ArrayList<MyTrend>();
    MyTrend myTwitterTrend;/* ww w .j a v a 2  s .c o  m*/
    GeoLocation geo = new GeoLocation(longi, lati);
    locations = twitter.getClosestTrends(geo);
    Trends trends = twitter.getPlaceTrends(locations.get(0).getWoeid());
    int count = 0;
    for (Trend trend : trends.getTrends()) {
        if (count < 5) {
            myTwitterTrend = new MyTrend(trend.getName(), trend.getURL());
            myTrend.add(myTwitterTrend);
            count++;
            availableTrends.add(trend.getName());
        }
    }
    System.out.println(" available Trends :" + availableTrends);
    return myTrend;
}

From source file:twitter4j.examples.trends.GetPlaceTrends.java

/**
 * Usage: java twitter4j.examples.trends.GetPlaceTrends [WOEID=0]
 *
 * @param args message//from  w ww .j  a  v  a2  s  .c  o m
 */
public static void main(String[] args) {
    try {
        int woeid = args.length > 0 ? Integer.parseInt(args[0]) : 1;
        Twitter twitter = new TwitterFactory().getInstance();
        Trends trends = twitter.getPlaceTrends(woeid);

        System.out.println("Showing trends for " + trends.getLocation().getName());

        for (Trend trend : trends.getTrends()) {
            System.out.println(String.format("%s (tweet_volume: %d)", trend.getName(), trend.getTweetVolume()));
        }

        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get trends: " + te.getMessage());
        System.exit(-1);
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        System.out.println("WOEID must be number");
        System.exit(-1);
    }
}

From source file:twitterapidemo.TwitterAPIDemo.java

License:Apache License

public static void main(String[] args) throws IOException, TwitterException {

    //TwitterAPIDemo twitterApiDemo = new TwitterAPIDemo();

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(consumerSecret);
    Configuration configuration = builder.build();

    TwitterFactory twitterFactory = new TwitterFactory(configuration);
    Twitter twitter = twitterFactory.getInstance();
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

    Scanner sc = new Scanner(System.in);
    System.out.println(//from  w ww  .  j ava 2 s  .  c om
            "Enter your choice:\n1. To post tweet\n2.To search tweets\n3. Recent top 3 trends and number of posts of each trending topic");
    int choice = sc.nextInt();
    switch (choice) {
    case 1:
        System.out.println("What's happening: ");
        String post = sc.next();
        StatusUpdate statusUpdate = new StatusUpdate(post + "-Posted by TwitterAPI");
        Status status = twitter.updateStatus(statusUpdate);

        System.out.println("status.toString() = " + status.toString());
        System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName());
        System.out.println("status.getSource() = " + status.getSource());
        System.out.println("status.getText() = " + status.getText());
        System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors()));
        System.out.println("status.getCreatedAt() = " + status.getCreatedAt());
        System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId());
        System.out.println("status.getGeoLocation() = " + status.getGeoLocation());
        System.out.println("status.getId() = " + status.getId());
        System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId());
        System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId());
        System.out.println("status.getPlace() = " + status.getPlace());
        System.out.println("status.getRetweetCount() = " + status.getRetweetCount());
        System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus());
        System.out.println("status.getUser() = " + status.getUser());
        System.out.println("status.getAccessLevel() = " + status.getAccessLevel());
        System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities()));
        System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities()));
        if (status.getRateLimitStatus() != null) {
            System.out.println(
                    "status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit());
            System.out.println("status.getRateLimitStatus().getRemaining() = "
                    + status.getRateLimitStatus().getRemaining());
            System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = "
                    + status.getRateLimitStatus().getResetTimeInSeconds());
            System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = "
                    + status.getRateLimitStatus().getSecondsUntilReset());
        }
        System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities()));
        System.out.println(
                "status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities()));
        break;
    case 2:
        System.out.println("Enter keyword");
        String keyword = sc.next();
        try {
            Query query = new Query(keyword);
            QueryResult result;
            do {
                result = twitter.search(query);
                List<Status> tweets = result.getTweets();
                for (Status tweet : tweets) {
                    System.out.println(tweet.getCreatedAt() + ":\t@" + tweet.getUser().getScreenName() + " - "
                            + tweet.getText());
                }
            } while ((query = result.nextQuery()) != null);
            System.exit(0);
        } catch (TwitterException te) {
            System.out.println("Failed to search tweets: " + te.getMessage());
            System.exit(-1);
            break;
        }
    case 3:
        //WOEID for India = 23424848
        Trends trends = twitter.getPlaceTrends(23424848);
        int count = 0;
        for (Trend trend : trends.getTrends()) {
            if (count < 3) {
                Query query = new Query(trend.getName());
                QueryResult result;
                int numberofpost = 0;
                do {
                    result = twitter.search(query);
                    List<Status> tweets = result.getTweets();
                    for (Status tweet : tweets) {
                        numberofpost++;
                    }
                } while ((query = result.nextQuery()) != null);
                System.out
                        .println("Number of post for the topic '" + trend.getName() + "' is: " + numberofpost);
                count++;
            } else
                break;
        }
        break;
    default:
        System.out.println("Invalid input");
    }
}