Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 70 additions & 66 deletions src/main/java/me/jhenrique/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,75 @@
import me.jhenrique.model.Tweet;

public class Main {
private static final String USERNAME = "Username: ";
private static final String RETWEETS = "Retweets: ";
private static final String TEXT = "Text: ";
private static final String MENTIONS = "Mentions: ";
private static final String HASHTAGS = "Hashtags: ";
private static final String USERNAME = "Username: ";
private static final String RETWEETS = "Retweets: ";
private static final String TEXT = "Text: ";
private static final String MENTIONS = "Mentions: ";
private static final String HASHTAGS = "Hashtags: ";
private static final String POSTTIME = "PostTime:";

public static void main(String[] args) {
/**
* Reusable objects
*/
TwitterCriteria criteria = null;
Tweet t = null;

/**
* Example 1 - Get tweets by username
**/

criteria = TwitterCriteria.create()
.setUsername("barackobama")
.setMaxTweets(1);
t = TweetManager.getTweets(criteria).get(0);

System.out.println("### Example 1 - Get tweets by username [barackobama]");
System.out.println(POSTTIME+t.getPostTime());
System.out.println(USERNAME + t.getUsername());
System.out.println(RETWEETS + t.getRetweets());
System.out.println(TEXT + t.getText());
System.out.println(MENTIONS + t.getMentions());
System.out.println(HASHTAGS + t.getHashtags());
System.out.println();

/**
* Example 2 - Get tweets by query search
**/
criteria = TwitterCriteria.create()
.setQuerySearch("europe refugees")
.setSince("2015-05-01")
.setUntil("2015-09-30")
.setMaxTweets(1);
t = TweetManager.getTweets(criteria).get(0);

System.out.println("### Example 2 - Get tweets by query search [europe refugees]");
System.out.println(POSTTIME+t.getPostTime());
System.out.println(USERNAME + t.getUsername());
System.out.println(RETWEETS + t.getRetweets());
System.out.println(TEXT + t.getText());
System.out.println(MENTIONS + t.getMentions());
System.out.println(HASHTAGS + t.getHashtags());
System.out.println();

/**
* Example 3 - Get tweets by username and bound dates
**/
criteria = TwitterCriteria.create()
.setUsername("barackobama")
.setSince("2015-09-10")
.setUntil("2015-09-12")
.setMaxTweets(1);
t = TweetManager.getTweets(criteria).get(0);

System.out.println("### Example 3 - Get tweets by username and bound dates [barackobama, '2015-09-10', '2015-09-12']");
System.out.println(POSTTIME+t.getPostTime());
System.out.println(USERNAME + t.getUsername());
System.out.println(RETWEETS + t.getRetweets());
System.out.println(TEXT + t.getText());
System.out.println(MENTIONS + t.getMentions());
System.out.println(HASHTAGS + t.getHashtags());
System.out.println();
}

public static void main(String[] args) {
/**
* Reusable objects
*/
TwitterCriteria criteria = null;
Tweet t = null;

/**
* Example 1 - Get tweets by username
**/

criteria = TwitterCriteria.create()
.setUsername("barackobama")
.setMaxTweets(1);
t = TweetManager.getTweets(criteria).get(0);

System.out.println("### Example 1 - Get tweets by username [barackobama]");
System.out.println(USERNAME + t.getUsername());
System.out.println(RETWEETS + t.getRetweets());
System.out.println(TEXT + t.getText());
System.out.println(MENTIONS + t.getMentions());
System.out.println(HASHTAGS + t.getHashtags());
System.out.println();

/**
* Example 2 - Get tweets by query search
**/
criteria = TwitterCriteria.create()
.setQuerySearch("europe refugees")
.setSince("2015-05-01")
.setUntil("2015-09-30")
.setMaxTweets(1);
t = TweetManager.getTweets(criteria).get(0);

System.out.println("### Example 2 - Get tweets by query search [europe refugees]");
System.out.println(USERNAME + t.getUsername());
System.out.println(RETWEETS + t.getRetweets());
System.out.println(TEXT + t.getText());
System.out.println(MENTIONS + t.getMentions());
System.out.println(HASHTAGS + t.getHashtags());
System.out.println();

/**
* Example 3 - Get tweets by username and bound dates
**/
criteria = TwitterCriteria.create()
.setUsername("barackobama")
.setSince("2015-09-10")
.setUntil("2015-09-12")
.setMaxTweets(1);
t = TweetManager.getTweets(criteria).get(0);

System.out.println("### Example 3 - Get tweets by username and bound dates [barackobama, '2015-09-10', '2015-09-12']");
System.out.println(USERNAME + t.getUsername());
System.out.println(RETWEETS + t.getRetweets());
System.out.println(TEXT + t.getText());
System.out.println(MENTIONS + t.getMentions());
System.out.println(HASHTAGS + t.getHashtags());
System.out.println();
}

}
9 changes: 7 additions & 2 deletions src/main/java/me/jhenrique/manager/TweetManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.jhenrique.manager;

import java.net.URLEncoder;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -102,7 +103,9 @@ public static List<Tweet> getTweets(TwitterCriteria criteria) {
}

Date date = new Date(dateMs);

Time time = new Time(dateMs);


Tweet t = new Tweet();
t.setId(id);
t.setPermalink("https://twitter.com"+permalink);
Expand All @@ -114,7 +117,9 @@ public static List<Tweet> getTweets(TwitterCriteria criteria) {
t.setMentions(processTerms("(@\\w*)", txt));
t.setHashtags(processTerms("(#\\w*)", txt));
t.setGeo(geo);

t.setPostTime(time);


results.add(t);

if (criteria.getMaxTweets() > 0 && results.size() >= criteria.getMaxTweets()) {
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/me/jhenrique/model/Tweet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.jhenrique.model;

import java.sql.Time;
import java.util.Date;

/**
Expand Down Expand Up @@ -28,6 +29,9 @@ public class Tweet {
private String hashtags;

private String geo;

private Time postTime;


public Tweet() {
}
Expand Down Expand Up @@ -111,5 +115,12 @@ public String getGeo() {
public void setGeo(String geo) {
this.geo = geo;
}


public Time getPostTime() {
return postTime;
}

public void setPostTime(Time postTime) {
this.postTime = postTime;
}
}