Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

10/3/21, 11:49 PM tugas3.

ipynb - Colaboratory

import tweepy
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

access_token = "3173432284-m5HfefqgNCuWxThvBuJ7xFyGlxaEnEk0gAPqgCV"
access_token_secret = "giZvEE6jmmrlSqOsZ6Nc0Zz2mHBZVUo8VF0EugvbQmF7h"
consumer_key = "sbvwv6nXpX2aLf6YVcFZK5kFK"
consumer_secret = "E1SAp12csHqO1HqCfwnz3ni4e03BVpFEoxM0kpruTyYbm4BcuQ"

class StdOutListener(StreamListener):
  def on_data(self, data):
    print(data)
    return True

  def on_error(self, status):
    print(status)

if __name__=='__main__':

  l=StdOutListener()
  auth = OAuthHandler(consumer_key, consumer_secret)
  auth.set_access_token(access_token, access_token_secret)
  stream = Stream(auth, l)
  stream.filter(track=['data science','machine learning'])

https://colab.research.google.com/drive/1NCgRZydVopMAeJ_qv8Kjwmo0y3NEAfsi#scrollTo=euQP3vN_CtV4&printMode=true 1/2
10/3/21, 11:49 PM tugas3.ipynb - Colaboratory

{"created_at":"Sun Oct 03 16:46:12 +0000 2021","id":1444705353103511561,"id_str":"144

{"created_at":"Sun Oct 03 16:46:16 +0000 2021","id":1444705372409827329,"id_str":"144

{"created_at":"Sun Oct 03 16:46:19 +0000 2021","id":1444705383487049731,"id_str":"144

{"created_at":"Sun Oct 03 16:46:21 +0000 2021","id":1444705391833751554,"id_str":"144

{"created_at":"Sun Oct 03 16:46:28 +0000 2021","id":1444705421210501121,"id_str":"144

{"created_at":"Sun Oct 03 16:46:30 +0000 2021","id":1444705429829955585,"id_str":"144

{"created_at":"Sun Oct 03 16:46:32 +0000 2021","id":1444705440084942850,"id_str":"144

{"created_at":"Sun Oct 03 16:46:38 +0000 2021","id":1444705461631168512,"id_str":"144

{"created_at":"Sun Oct 03 16:46:40 +0000 2021","id":1444705471307390978,"id_str":"144

{"created_at":"Sun Oct 03 16:46:41 +0000 2021","id":1444705476390838281,"id_str":"144

{"created_at":"Sun Oct 03 16:46:49 +0000 2021","id":1444705508330549251,"id_str":"144

---------------------------------------------------------------------------

KeyboardInterrupt Traceback (most recent call last)

<ipython-input-4-a102175270d9> in <module>()

13 auth.set_access_token(access_token, access_token_secret)

14 stream = Stream(auth, l)

---> 15 stream.filter(track=['data science','machine learning'])

13 frames
/usr/lib/python3.7/ssl.py in read(self, len, buffer)

927 try:

928 if buffer is not None:

--> 929 return self._sslobj.read(len, buffer)

930 else:

931 return self._sslobj.read(len)

KeyboardInterrupt:
error 1m 1s completed at 11:47 PM

https://colab.research.google.com/drive/1NCgRZydVopMAeJ_qv8Kjwmo0y3NEAfsi#scrollTo=euQP3vN_CtV4&printMode=true 2/2

You might also like