Skip to content

Commit

Permalink
- Added a new attribute on Tweet model: geo (Location name)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefferson-Henrique committed Nov 11, 2015
1 parent 8ce970e commit 669798c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/me/jhenrique/main/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public static void main(String[] args) {

try {
BufferedWriter bw = new BufferedWriter(new FileWriter("output_got.csv"));
bw.write("username;date;retweets;favorites;text");
bw.write("username;date;retweets;favorites;text;geo");
bw.newLine();

System.out.println("Searching... \n");
for (Tweet t : TweetManager.getTweets(criteria)) {
bw.write(String.format("%s;%s;%d;%d;\"%s\"", t.getUsername(), sdf.format(t.getDate()), t.getRetweets(), t.getFavorites(), t.getText()));
bw.write(String.format("%s;%s;%d;%d;\"%s\";%s", t.getUsername(), sdf.format(t.getDate()), t.getRetweets(), t.getFavorites(), t.getText(), t.getGeo()));
bw.newLine();
}

Expand Down
9 changes: 8 additions & 1 deletion src/me/jhenrique/manager/TweetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,16 @@ public static List<Tweet> getTweets(TwitterCriteria criteria) {
int retweets = Integer.valueOf(tweet.select("span.ProfileTweet-action--retweet span.ProfileTweet-actionCount").attr("data-tweet-stat-count").replaceAll(",", ""));
int favorites = Integer.valueOf(tweet.select("span.ProfileTweet-action--favorite span.ProfileTweet-actionCount").attr("data-tweet-stat-count").replaceAll(",", ""));
long dateMs = Long.valueOf(tweet.select("small.time span.js-short-timestamp").attr("data-time-ms"));

String geo = "";
Elements geoElement = tweet.select("span.Tweet-geo");
if (geoElement.size() > 0) {
geo = geoElement.attr("title");
}

Date date = new Date(dateMs);

Tweet t = new Tweet(usernameTweet, txt, date, retweets, favorites);
Tweet t = new Tweet(usernameTweet, txt, date, retweets, favorites, geo);
results.add(t);

if (criteria.getMaxTweets() > 0 && results.size() >= criteria.getMaxTweets()) {
Expand Down
13 changes: 12 additions & 1 deletion src/me/jhenrique/model/Tweet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ public class Tweet {

private int favorites;

private String geo;

public Tweet() {
}

public Tweet(String username, String text, Date date, int retweets,
int favorites) {
int favorites, String geo) {
this.username = username;
this.text = text;
this.date = date;
this.retweets = retweets;
this.favorites = favorites;
this.geo = geo;
}

public String getUsername() {
Expand Down Expand Up @@ -71,4 +74,12 @@ public void setFavorites(int favorites) {
this.favorites = favorites;
}

public String getGeo() {
return geo;
}

public void setGeo(String geo) {
this.geo = geo;
}

}

0 comments on commit 669798c

Please sign in to comment.