Lately, I've been messing around with the requests and regex libraries for Python. They are awesome. So, without any further explanation, I present this short script that uses both in an attempt to identify people drunk-tweeting in Chicago. Enjoy.

# drunktweet.py ''' Print out possible drunk tweets from the city of Chicago. ''' import regex import requests import json # Terms for being "wasted" terms = { 'drunk','wasted','buzzed','hammered','plastered' } # A fuzzy regex for people who can't type pat = regex.compile(r"(?:\L<terms>){i,d,s,e<=2}$", regex.I, terms=terms) # Connect to the Twitter streaming API url = "https://stream.twitter.com/1/statuses/filter.json" parms = { 'locations' : "-87.94,41.644,-87.523,42.023" # Chicago } auth = ('username','password') r = requests.post(url, data=parms, auth=auth) # Print possible candidates for line in r.iter_lines(): if line: tweet = json.loads(line) status = tweet.get('text',u'') words = status.split() if any(pat.match(word) for word in words): print(tweet['user']['screen_name'], status)

It's left as an exercise to reader to filter out false-positives and have the script call a cab. By the way, you should check out some of my Python Classes in Chicago.