Created
September 26, 2017 06:32
-
-
Save MKtalk/8b844d7d3e5970c82db01cbabdc9e087 to your computer and use it in GitHub Desktop.
Simple twitter feed bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import (absolute_import, division, print_function, unicode_literals) | |
from bothub_client.bot import BaseBot | |
import tweepy | |
class Bot(BaseBot): | |
consumer_key = '<your key>' | |
consumer_secret = '<your secret>' | |
access_token = '<your token>' | |
access_token_secret = '<your token secret>' | |
def handle_message(self, event, context): | |
message = event.get('content') | |
if message == 'feed': | |
feed = self.get_my_feed() | |
else: | |
self.send_message('Not yet supported.') | |
def get_my_feed(self): | |
auth = tweepy.OAuthHandler(self.consumer_key, self.consumer_secret) | |
auth.set_access_token(self.access_token, self.access_token_secret) | |
api = tweepy.API(auth) | |
public_tweets = api.home_timeline() | |
for tweet in public_tweets: | |
self.send_message('{}: {}'.format(tweet.user.screen_name, tweet.text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment