I'm trying to listen to a live twitter feed using streamR :: filterStream (), parse these feeds using streamR :: parseTweets (), and then print all new tweets every second on the console screen. So far I have two files. First:
library(twitteR) library(ROAuth) library(streamR) #load in RData file that contains the ROAuth object called cred load("PATH_TO_CREDENTIALS_RData_FILE") registerTwitterOAuth(cred) filterStream(file="goog_tweets.json", track="goog", timeout=3600, oauth=cred)
and the second, which causes the first, is the following:
library(streamR) system("R CMD BATCH /home/yourname/twitter/public_listener.R", wait = F) tweets.df <- parseTweets("goog_tweets.json") while(TRUE){ newtweets <- parseTweets("goog_tweets.json", verbose = "FALSE") if(nrow(newtweets) > nrow(tweets.df)){ diff <- nrow(newtweets) - nrow(tweets.df) seq <- 1:diff print(newtweets[seq,]$text) } tweets.df <- newtweets Sys.sleep(2) }
How to make the second script "recognize" when the listener is waiting time? How can I make this "better"? Otherwise, the while loop will execute forever.
source share