Advertisement
9terz

Untitled

May 30th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #coding=utf-8
  2. import tweepy, re, time, ConfigParser
  3. from urllib import urlopen
  4. from bs4 import BeautifulSoup
  5. import json
  6. import re, urlparse
  7.  
  8. # Authentication details. To obtain these visit dev.twitter.com
  9. consumer_key =
  10. consumer_secret =
  11.  
  12. access_token =
  13. access_token_secret =
  14.  
  15. def urlEncodeNonAscii(b):
  16. return re.sub('[\x80-\xFF]', lambda c: '%%%02x' % ord(c.group(0)), b)
  17.  
  18. def iriToUri(iri):
  19. parts= urlparse.urlparse(iri)
  20. return urlparse.urlunparse(
  21. part.encode('idna') if parti==1 else urlEncodeNonAscii(part.encode('utf-8'))
  22. for parti, part in enumerate(parts)
  23. )
  24.  
  25.  
  26. # This is the listener, resposible for receiving data
  27. class StdOutListener(tweepy.StreamListener):
  28. def on_data(self, data):
  29. print "login OK"
  30. # Twitter returns data in JSON format - we need to decode it first
  31. decoded = json.loads(data)
  32.  
  33. # Also, we convert UTF-8 to ASCII ignoring all bad characters sent by users
  34. print '@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore'))
  35. user = decoded['user']['screen_name']
  36. if user == user1:
  37. api.update_status(status="@"+user+" Kuy rai..")
  38. user2 = user1
  39. elif user == user2:
  40. api.update_status(status="@"+user+" Kuy rai...")
  41. user3 = user2
  42. else:
  43. api.update_status(status="@"+user+" Kuy rai")
  44. user1 = user
  45. print ''
  46. return True
  47.  
  48. def on_error(self, status):
  49. print status
  50.  
  51. if __name__ == '__main__':
  52. user1 = 'a'
  53. user2 = 'b'
  54. user3 = 'c'
  55. l = StdOutListener()
  56. auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  57. auth.set_access_token(access_token, access_token_secret)
  58.  
  59. auth.secure = True
  60. api = tweepy.API(auth)
  61.  
  62. name = urlEncodeNonAscii('เทส')
  63. print "Showing all new tweets for Help me jarvis"
  64.  
  65. # There are different kinds of streams: public stream, user stream, multi-user streams
  66. # In this example follow #programming tag
  67. # For more details refer to https://dev.twitter.com/docs/streaming-apis
  68. stream = tweepy.Stream(auth, l)
  69. stream.filter(track=['jarvis'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement