Skip to content Skip to sidebar Skip to footer

How Do I Filter Tweets Using Location And Keyword?

I'm a new Python user and have been experimenting with tweepy. I understand the twitter API does not allow for filtering on both location and keywords. To get around this, I've a

Solution 1:

Use Regular expressions to search the tweet. as follows

    import re
    keyword = ["iPhone", "Samsung", "HTC", "Sony", "Blackberry"]
    patterns = [r'\b%s\b' % re.escape(s.strip()) for s in keyword.lower()]
    there = re.compile('|'.join(patterns))
    stream=["i have a iPhone","i dont like Samsung","HTC design are awesome","Sony camera is good","Blackberry lost market","Nokia soldout to windows"]
    for i in stream:
        if there.search(i):
            print("Tweet Found  %r" % (i))

Post a Comment for "How Do I Filter Tweets Using Location And Keyword?"