Skip to content

Instantly share code, notes, and snippets.

@Zulko
Forked from seanmckaybeck/analyze.py
Last active August 29, 2015 14:05
Show Gist options
  • Save Zulko/f8735acf94cc97d6c53d to your computer and use it in GitHub Desktop.
Save Zulko/f8735acf94cc97d6c53d to your computer and use it in GitHub Desktop.
'''
Rewrite with Twittcher ;)
Result (every 20 seconds):
>>> Most common words: [('ferguson', 41), ('http', 28), ('protests', 9),
('missouri', 9), ('leave', 8), ('continue', 8),...]
'''
import re
from collections import Counter
from twittcher import SearchWatcher
counter = Counter()
def action(tweet):
words = [w for w in re.findall("\w+",tweet.text) if len(w)>3]
counter.update([w.lower() for w in words])
print ("Most common words: %s"%(counter.most_common(20)))
bot = SearchWatcher("ferguson", action=action)
bot.watch_every(20) # 20 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment