Recaling tweets from a text file and then animating them individually.
in
Contributed Library Questions
•
3 months ago
Hi,
I am trying to create an installation that saves up tweets on a particular topic and stores them in a text file. I have this working using coll in Max msp to save the files from Processing. When a bucket is poured(via arduino) I would like the tweets to fall down the screen like rain. I can store and update the txt file fine, but the problems I am having is to retrieve the tweets one by one and get them to fall down the screen. Also I would like the tweets to be deleted from the text file after they have fallen to the bottom of the screen.
Any help would be very much appreciated thankyou!
I am trying to create an installation that saves up tweets on a particular topic and stores them in a text file. I have this working using coll in Max msp to save the files from Processing. When a bucket is poured(via arduino) I would like the tweets to fall down the screen like rain. I can store and update the txt file fine, but the problems I am having is to retrieve the tweets one by one and get them to fall down the screen. Also I would like the tweets to be deleted from the text file after they have fallen to the bottom of the screen.
Any help would be very much appreciated thankyou!
- import processing.pdf.*;
import java.util.Date;
import maxlink.*;
MaxLink link = new MaxLink(this, "twits");
MaxLink linkin = new MaxLink(this, "twoots");
static String OAuthConsumerKey = "mykey";
static String OAuthConsumerSecret = "secret";
static String AccessToken = "at";
static String AccessTokenSecret = "dd";
String myTimeline;
java.util.List statuses = null;
User[] friends;
TwitterFactory twitterFactory;
Twitter twitter;
RequestToken requestToken;
String[] theSearchTweets = new String[11];
String myQueryWord = "#water";
long previousIdOfTweetContainingQuery = 0;
public ArrayList tweets;
public String msg; //the tweets
public int a; // from max msp;
public int y = 0; // to move words down page
public int x = 0; //
public float speed; // to create random speeds
private static AccessToken loadAccessToken() {
return new AccessToken(AccessToken, AccessTokenSecret); // get my oauth details
}
void setup() {
size(600, 600);
frameRate(60);
background(0);
linkin.declareInlet("a"); //connection to Max msp
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(OAuthConsumerKey);
cb.setOAuthConsumerSecret( OAuthConsumerSecret );
cb.setOAuthAccessToken( AccessToken);
cb.setOAuthAccessTokenSecret( AccessTokenSecret );
twitterFactory = new TwitterFactory(cb.build());
twitter = twitterFactory.getInstance();
println("connected");
}
void draw() {
getSearch(); // retrieve tweets to max and sore them in "tweets.txt"
y =y +7; // increase y position of tweets
String[] lines = loadStrings("tweeters.txt"); //This doesn't work at all really but is the kind of thing I want to do.
for (int i = 0; i < lines.length; i++) {
text(lines[i], random(600), y, 50, 50);
}
}
void getSearch() {
try {
println ("Searching.... Current time = " + hour() + ":" + minute() + ":" + second());
Query query = new Query(myQueryWord);
query.count(50); // how many results to fetch
QueryResult result = twitter.search(query);
ArrayList tweetsContainingQuery = (ArrayList) result.getTweets();
if (tweetsContainingQuery.size() > 0) {
Status mostRecentTweetContainingQuery = (Status) tweetsContainingQuery.get(0);
long mostRecentTweetContainingQueryId = mostRecentTweetContainingQuery.getId();
if (previousIdOfTweetContainingQuery == 0) {
previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId;
}
if (mostRecentTweetContainingQueryId != previousIdOfTweetContainingQuery) {
// my word is tweeted
previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId;
Date d = mostRecentTweetContainingQuery.getCreatedAt();
msg = mostRecentTweetContainingQuery.getText();
link.output(msg); // send and store in coll/"tweeters.txt"
}
}
}
catch (TwitterException te) {
println("Error connecting to Twitter: " + te); //let me know if somethings not right
};
delay(3000);
}
1