Skip to content

Instantly share code, notes, and snippets.

@kleong
Created July 30, 2019 20:23
Show Gist options
  • Save kleong/c3d6ef2347c30845ec2990b0a820dbad to your computer and use it in GitHub Desktop.
Save kleong/c3d6ef2347c30845ec2990b0a820dbad to your computer and use it in GitHub Desktop.
# twitter api credentials
access_token=...
access_token_secret=...
consumer_key=...
consumer_secret=...
class TweetListener(StreamListener):
def __init__(self, stream_name):
self.kinesis = boto3.client('kinesis')
self.stream_name = stream_name
def on_data(self, data):
record = {}
record['Data'] = data
record['PartitionKey'] = ''.join(random.choice(chars) for _ in range(size))
self.kinesis.put_records(Records=[record], StreamName=self.stream_name)
auth=OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream=Stream(auth, TweetListener("twitter-stream"))
search_terms=["music", "facebook", "apple"]
stream.filter(track=search_terms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment