<s> import json <EOL> import tweepy <EOL> import socket <EOL> import sys <EOL> from utils import Util <EOL> def initialize ( ) : <EOL> with open ( '<STR_LIT>' ) as config_data : <EOL> config = json . load ( config_data ) <EOL> auth = tweepy . OAuthHandler ( config [ '<STR_LIT>' ] , config [ '<STR_LIT>' ] ) <EOL> auth . set_access_token ( config [ '<STR_LIT>' ] , config [ '<STR_LIT>' ] ) <EOL> api = tweepy . API ( auth ) <EOL> stream = TwitterStreamListener ( ) <EOL> twitter_stream = tweepy . Stream ( auth = api . auth , listener = stream ) <EOL> twitter_stream . filter ( track = [ '<STR_LIT>' ] , async = True ) <EOL> class TwitterStreamListener ( tweepy . StreamListener ) : <EOL> def on_data ( self , data ) : <EOL> text_i = data . find ( "<STR_LIT:text>" ) <EOL> source_i = data . find ( "<STR_LIT:source>" ) <EOL> text = data [ text_i + <NUM_LIT:8> : source_i ] . decode ( '<STR_LIT>' ) <EOL> sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> server_address = ( '<STR_LIT:localhost>' , <NUM_LIT> ) <EOL> print >> sys . stderr , '<STR_LIT>' % server_address <EOL> sock . connect ( server_address ) <EOL> try : <EOL> print >> sys . stderr , '<STR_LIT>' % text <EOL> sock . sendall ( Util . normalize ( text ) + '<STR_LIT:\n>' ) <EOL> finally : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sock . close ( ) <EOL> def on_error ( self , status_code ) : <EOL> if status_code == <NUM_LIT> : <EOL> return False <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> initialize ( ) </s>
