Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #coding=utf-8
- import tweepy, re, time, ConfigParser
- from urllib import urlopen
- from bs4 import BeautifulSoup
- import json
- import re, urlparse
- # Authentication details. To obtain these visit dev.twitter.com
- consumer_key =
- consumer_secret =
- access_token =
- access_token_secret =
- def urlEncodeNonAscii(b):
- return re.sub('[\x80-\xFF]', lambda c: '%%%02x' % ord(c.group(0)), b)
- def iriToUri(iri):
- parts= urlparse.urlparse(iri)
- return urlparse.urlunparse(
- part.encode('idna') if parti==1 else urlEncodeNonAscii(part.encode('utf-8'))
- for parti, part in enumerate(parts)
- )
- # This is the listener, resposible for receiving data
- class StdOutListener(tweepy.StreamListener):
- def on_data(self, data):
- print "login OK"
- # Twitter returns data in JSON format - we need to decode it first
- decoded = json.loads(data)
- # Also, we convert UTF-8 to ASCII ignoring all bad characters sent by users
- print '@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore'))
- user = decoded['user']['screen_name']
- if user == user1:
- api.update_status(status="@"+user+" Kuy rai..")
- user2 = user1
- elif user == user2:
- api.update_status(status="@"+user+" Kuy rai...")
- user3 = user2
- else:
- api.update_status(status="@"+user+" Kuy rai")
- user1 = user
- print ''
- return True
- def on_error(self, status):
- print status
- if __name__ == '__main__':
- user1 = 'a'
- user2 = 'b'
- user3 = 'c'
- l = StdOutListener()
- auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
- auth.set_access_token(access_token, access_token_secret)
- auth.secure = True
- api = tweepy.API(auth)
- name = urlEncodeNonAscii('เทส')
- print "Showing all new tweets for Help me jarvis"
- # There are different kinds of streams: public stream, user stream, multi-user streams
- # In this example follow #programming tag
- # For more details refer to https://dev.twitter.com/docs/streaming-apis
- stream = tweepy.Stream(auth, l)
- stream.filter(track=['jarvis'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement