Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restarting fetch to different filtering needs #1

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

Restarting fetch to different filtering needs #1

gawry opened this issue Oct 5, 2012 · 2 comments

Comments

@gawry
Copy link

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
Copy link

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
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants