Skip to content

Instantly share code, notes, and snippets.

@markng
Created January 11, 2010 03:40
Show Gist options
  • Save markng/273981 to your computer and use it in GitHub Desktop.
Save markng/273981 to your computer and use it in GitHub Desktop.
import time
from textwrap import TextWrapper
import re
import tweepy
import urllib, urllib2
swap_list = ["sausage", "house", "banana", "car", "computer"]
swap_list_re = '|'.join(swap_list)
swap_re = re.compile('(%s)' % swap_list_re, re.I)
class StreamWatcherListener(tweepy.StreamListener):
status_wrapper = TextWrapper(width=50, initial_indent=' ', subsequent_indent=' ')
def on_status(self, status):
try:
message = re.sub(swap_re,'penis',status.text)
print message
message = '<br />'.join(re.split('\r\n|\n|\r', message))
message = '<div class="hentry"><img class="photo fn" src="http://s.twimg.com/a/1260307830/images/default_profile_1_bigger.png" width="48" height
="48 "/>%s</div>' % (message)
values = { 'channel' : "penis", 'message' : message }
data = urllib.urlencode(values)
req = urllib2.Request('http://twfv.eu/hm1backend/admin/send', data)
response = urllib2.urlopen(req)
except:
# Catch any unicode errors while printing to console
# and just ignore them to avoid breaking application.
pass
def on_error(self, status_code):
print 'An error has occured! Status code = %s' % status_code
return True # keep stream alive
def on_timeout(self):
print 'Snoozing Zzzzzz'
def main():
# Prompt for login credentials and setup stream object
username = 'markng'
password = 'password'
stream = tweepy.Stream(username, password, StreamWatcherListener(), timeout=None)
follow_list = None
stream.filter(follow_list, swap_list)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print '\nGoodbye!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment