001package org.openimaj.picslurper;
002
003import java.io.IOException;
004
005import org.apache.http.client.ClientProtocolException;
006import org.apache.log4j.Logger;
007import org.joda.time.DateTime;
008import org.openimaj.text.nlp.TweetTokeniserException;
009
010/**
011 * @author Sina Samangooei (ss@ecs.soton.ac.uk)
012 * 
013 */
014public class PicslurperTwitterHarness {
015
016        static Logger logger = Logger.getLogger(PicslurperTwitterHarness.class);
017
018        private PicslurperTwitterHarness() {
019        }
020
021        /**
022         * Instantiates a {@link PicSlurper} tool which reads from a stream which
023         * this class constructs. The {@link TwitterInputStreamFactory} is used
024         * which is called again if the connection is dropped for whatever reason
025         * 
026         * @param args
027         * @throws ClientProtocolException
028         * @throws IOException
029         * @throws TweetTokeniserException
030         * @throws InterruptedException
031         */
032        public static void main(String args[]) throws ClientProtocolException, IOException, TweetTokeniserException,
033                        InterruptedException
034        {
035                final TwitterInputStreamFactory factory = TwitterInputStreamFactory.streamFactory();
036                if (factory == null)
037                        return;
038                logger.debug("TwitterInputStreamFactory prepared...");
039                while (true) {
040                        try {
041                                logger.debug("Establishing twitter connection at: " + new DateTime());
042                                System.setIn(factory.nextInputStream());
043                                PicSlurper.main(args);
044                        } catch (final Throwable e) {
045                        } finally {
046                        }
047                        logger.debug("Connection down, waiting 30 seconds....");
048                        Thread.sleep(30000);
049                }
050        }
051}