Restarting fetch to different filtering needs #1

Open
gawry opened this Issue Oct 5, 2012 · 2 comments

Comments

Projects
None yet
2 participants

gawry commented Oct 5, 2012

It would be good to have a easy way to change tracked words once you are getting the stream feed.

knutole commented Oct 9, 2012

I've been thinking about this too, but it appears to me that Twitter does not support it - I can't find anything in their API to suggest it, at least. I'd love to be proved wrong though.

gawry commented Oct 9, 2012

I did a successful implementation, but doesn't seems very good as I don't stop the current connection.

    stream = tweetstream.TweetStream(configuration,ioloop=main_io_loop)

    stream.fetch("/1.1/statuses/filter.json?track="+tornado.escape.url_escape(words), callback=callback)

    def check_words():
        global words, stream
        with open('words.txt') as file:
            #using a file for testing purposes, real implementation should use access a db
            newwords = file.read()
        if words != newwords:
            words = newwords
            print newwords
            try:
                #start another process (and twitter kills the last one), it would be good to gracefully kill the current connection
                stream = tweetstream.TweetStream(configuration,ioloop=main_io_loop)
                stream.fetch("/1.1/statuses/filter.json?track="+tornado.escape.url_escape(words), callback=callback)
                interval_ms = 1000*60
                scheduler = tornado.ioloop.PeriodicCallback(check_words,interval_ms,io_loop = main_io_loop)
                scheduler.start()
                main_io_loop.start()
            except:
                pass
            file.close()

    interval_ms = 1000*60
    scheduler = tornado.ioloop.PeriodicCallback(check_words,interval_ms,io_loop = main_io_loop)
    scheduler.start()
    main_io_loop.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment