-
Notifications
You must be signed in to change notification settings - Fork 1
/
twitter.pde
129 lines (102 loc) · 3.56 KB
/
twitter.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
static String OAuthConsumerKey = "";
static String OAuthConsumerSecret = "";
static String AccessToken = "";
static String AccessTokenSecret = "";
Twitter twitter = new TwitterFactory().getInstance();
void connectTwitter() {
twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
AccessToken accessToken = loadAccessToken();
twitter.setOAuthAccessToken(accessToken);
}
private static AccessToken loadAccessToken() {
return new AccessToken(AccessToken, AccessTokenSecret);
}
ArrayList tweetAuthor;
ArrayList tweetText;
ArrayList tweetDate;
ArrayList tweetAuthorGeo;
int numberTweets;
void searchTwitter(String queryStr) {
tweetAuthor = new ArrayList();
tweetText = new ArrayList();
tweetDate = new ArrayList();
tweetAuthorGeo = new ArrayList();
numberTweets = 0;
try {
Query query = new Query(queryStr);
query.setRpp(numberTweets);
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
numberTweets = tweets.size();
for (int i=0; i<tweets.size(); i++) {
Tweet t = (Tweet)tweets.get(i);
tweetAuthor.add(t.getFromUser());
tweetText.add(t.getText());
Date d = t.getCreatedAt();
tweetDate.add(d.toString());
/*String date_split[] = (d.toString()).split(" ");
if (date_split[1].equals("Jan") == true) {
date_split[1] = "01";
}
else if (date_split[1].equals("Feb") == true) {
date_split[1] = "02";
}
else if (date_split[1].equals("Mar") == true) {
date_split[1] = "03";
}
else if (date_split[1].equals("Apr") == true) {
date_split[1] = "04";
}
else if (date_split[1].equals("May") == true) {
date_split[1] = "05";
}
else if (date_split[1].equals("Jun") == true) {
date_split[1] = "06";
}
else if (date_split[1].equals("Jul") == true) {
date_split[1] = "07";
}
else if (date_split[1].equals("Aug") == true) {
date_split[1] = "08";
}
else if (date_split[1].equals("Sep") == true) {
date_split[1] = "09";
}
else if (date_split[1].equals("Oct") == true) {
date_split[1] = "10";
}
else if (date_split[1].equals("Nov") == true) {
date_split[1] = "11";
}
else if (date_split[1].equals("Dec") == true) {
date_split[1] = "12";
}
//String time = date_split[3];
String time_split[] = date_split[3].split(":");
//String hours = time_split[0];
//String mins = time_split[1];
//String sec = time_split[2];
// tweetDate = hora + " " + mes + " " + dia + ", " + ano;
tweetDate.add(new String(time_split[0] + " " + date_split[1] + " " + date_split[2] + ", " + date_split[0]));
*/
//tweetAuthorGeo.add(t.getPlace());
//list text
//println((t.getText()).substring(queryStr.length()+1));
//doesnt give anything, freezes
//println(t.getGeoLocation().toString());
//gives a lot of null's
//println(t.getLocation());
//doesnt give anything, freezes
//println((t.getPlace()).getCountry() + " " + (t.getPlace()).getFullName() );
//gives a lot of null's
//println(t.getPlace());
//returns en pl sv, useless
//println(t.getIsoLanguageCode());
//println(t.getGeoLocation());
User thisuser = twitter.showUser(t.getFromUser());
tweetAuthorGeo.add(thisuser.getLocation());
}
} catch (TwitterException e) {
println("Search tweets: " + e);
}
}