This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var interval = setInterval(function() { | |
// all my code | |
}, 3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var interval = setInterval(function update() { | |
// all my code | |
return update; | |
}(), 3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static TwitterStream getStream() { | |
ConfigurationBuilder cb = new ConfigurationBuilder(); | |
cb.setDebugEnabled(true); | |
cb.setOAuthConsumerKey("<YOUR CONSUMER KEY>"); | |
cb.setOAuthConsumerSecret("<YOUR CONSUMER SECRET>"); | |
cb.setOAuthAccessToken("<YOUR ACCESS TOKEN>"); | |
cb.setOAuthAccessTokenSecret("<YOUR ACCESS TOKEN SECRET>"); | |
return new TwitterStreamFactory(cb.build()).getInstance(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static TwitterStream twitter; | |
private static int numVinesScraped = 0; // see Step 4 | |
private static final int NUM_VINES_TO_DOWNLOAD = -1; // see Step 4 | |
private static final String SAVE_DIRECTORY = “vines/“; // see Step 4 | |
public static void main(String[] args) { | |
// Connects to the Streaming API | |
twitter = TwitterStreamBuilderUtil.getStream(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sets keyword to track | |
FilterQuery fq = new FilterQuery(); | |
String keyword[] = { “http” }; | |
fq.track(keyword); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TweetBuffer { | |
private int id; | |
private String saveDirectory; | |
private HashSet<Status> tweets; | |
private boolean isProcessing; | |
// constructor | |
public TweetBuffer(int id, String saveDirectory) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static TweetBuffer buffer1, buffer2; | |
private static int currentBufferId; // 1 or 2 | |
private static final int MIN_BUFFER_SIZE = 10; | |
private static HashSet<String> duplicateUrls; // holds Vine URLs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// instantiates buffers | |
buffer1 = new TweetBuffer(1, SAVE_DIRECTORY); | |
buffer2 = new TweetBuffer(2, SAVE_DIRECTORY); | |
currentBufferId = 1; | |
duplicateUrls = new HashSet < String > (); | |
// instantiates listener to fill and process the buffers | |
StatusListener listener = new StatusListener() { | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void processCurrentBuffer() { | |
// Does nothing if the current buffer is already processing or | |
// if it contains fewer elements than the minimum buffer size. | |
if ((currentBufferId == 1 && (buffer1.isProcessing() || buffer1 | |
.getTweets().size() < MIN_BUFFER_SIZE)) || | |
(currentBufferId == 2 && (buffer2.isProcessing() || buffer2 | |
.getTweets().size() < MIN_BUFFER_SIZE))) { | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ProcessingListener { | |
public void onProcessFinished(int bufferId, HashSet urls, | |
int numScraped); | |
} |
OlderNewer