Skip to content

Instantly share code, notes, and snippets.

@MKtalk
Created September 26, 2017 06:32
Show Gist options
  • Save MKtalk/8b844d7d3e5970c82db01cbabdc9e087 to your computer and use it in GitHub Desktop.
Save MKtalk/8b844d7d3e5970c82db01cbabdc9e087 to your computer and use it in GitHub Desktop.
Simple twitter feed bot
# -*- 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