Reading a text file that is being constantly updated
in
Programming Questions
•
3 months ago
I am not sure how to read a text file that is being updated elsewhere. The file is being updated every three seconds in which when the tweets fall to the bottom of the page the txt file is having it's first entry deleted. When I run it though the text file remains the same in processing until I restart the app.
Any help much appreciated thanks!
nb. I have posted this here instead of contributed library because maxlink is not relevant to the question. Sorry if it should not be here.
Any help much appreciated thanks!
nb. I have posted this here instead of contributed library because maxlink is not relevant to the question. Sorry if it should not be here.
- MaxLink linkin = new MaxLink(this, "tweets");
ArrayList<Tweets> tweets;
import maxlink.*;
void setup() {
size(600,600);
textAlign(CENTER);
tweets = new ArrayList<Tweets>();
tweets.add(new Tweets());
}
void draw() {
background(255);
fill(0);
for(int i = tweets.size()-1;i>=0;i--){
Tweets tweet = tweets.get(i);
tweet.getTweet(i);
}
}
void mousePressed(){
tweets.add(new Tweets());
}
class Tweets{
float x = 0;
float r = random(400);
String s = "empty";
int index = 0;
void getTweet(int index){
String [] headlines = loadStrings("tweets.txt");
textAlign(CENTER);
if((headlines[index].length() < 5) && (headlines[index].length() > 0)){
x = x+ random(8);
}
else if ((headlines[index].length() < 20) && (headlines[index].length() > 5)){
x = x+random(6);
}
else if ((headlines[index].length() < 60) && (headlines[index].length() > 20)){
x = x+random(4);
}
else if ((headlines[index].length() < 90) && (headlines[index].length() > 60)){
x = x+random(2.5);
}
else if (headlines[index].length() > 138){
x = x+random(0.5);
}
text(headlines[index],r,x);
if (x >height) {
x = 0;
r = random(400);
tweets.remove(index);
linkin.output(0);
}
if (index == (headlines.length-1)){
fill(0);
text(s, 400,400);
println("empty");
index = 1;
}
}
}
1