コード例 #1
0
ファイル: TwitterTest.java プロジェクト: nAk123/iwa-project
 /**
  * Gets list of trend names by Where On Earth ID
  *
  * @param woeid Where On Earth ID of the place to get trends
  * @return List of trend names
  * @throws TwitterException
  */
 private static List<String> getTrendsByWoeid(int woeid) throws TwitterException {
   List<String> trendNames = new ArrayList<String>();
   @SuppressWarnings("deprecation")
   Trends trends = twitter.getLocationTrends(woeid);
   Trend[] trend = trends.getTrends();
   for (Trend t : trend) {
     trendNames.add(t.toString());
   }
   return trendNames;
 }
コード例 #2
0
  public static void main(String[] args) throws Exception {

    Context context = new Context("conf/producer.conf");
    Tweety tp = new Tweety();

    try {
      Class.forName("com.mysql.jdbc.Driver");
      String url = "jdbc:mysql://172.20.95.137/mongo_test?" + "user=manoj&password=qwerty1!";
      Connection conn = DriverManager.getConnection(url);
      System.out.println(url);
      Statement stmt = conn.createStatement();

      ConfigurationBuilder cb = new ConfigurationBuilder();
      cb.setOAuthConsumerKey("ujS6V0corQ4v8K4dp6bIlVYsq");
      cb.setOAuthConsumerSecret("XhmTLcS4BI6zy9fZ0xIOy1ZZkAnQYZ1jFrlHojWuWpx2RCWH9H");
      cb.setOAuthAccessToken("30427118-YNLB3WfviD4j7MvNgU4gZ7SPQbCDBXWh4kPZcHXrY");
      cb.setOAuthAccessTokenSecret("LkhcZUJbj33RBc1DTXrxJps4ELgog8WxoRS6gCReemOHc");
      cb.setJSONStoreEnabled(true);
      cb.setIncludeEntitiesEnabled(true);
      cb.setHttpProxyHost("proxy.tcs.com");
      cb.setHttpProxyPort(8080);
      cb.setHttpProxyUser("467098");
      cb.setHttpProxyPassword("See@0615");
      Twitter twitter = new TwitterFactory(cb.build()).getInstance();
      ResponseList<Location> locations;
      locations = twitter.getAvailableTrends();
      System.out.println("Showing available trends");
      Trends trends = twitter.getPlaceTrends(2295386);
      stmt.executeUpdate("drop table hashtag");
      stmt.executeUpdate("create table hashtag(name varchar(50),count int)");
      for (int i = 0; i <= 5; i++) {
        System.out.println(trends.getTrends()[i].getName());
        hashtags[i] = trends.getTrends()[i].getName();
        stmt.executeUpdate("insert into hashtag values (\'" + hashtags[i] + "\'" + "," + 0 + ")");
      }
      System.out.println("done.");

    } catch (Exception te) {
      te.printStackTrace();
      System.out.println("Failed to get trends: " + te.getMessage());
      System.exit(-1);
    }
    tp.start(context);
  }