Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- # -*- coding: utf-8 -*- #
- from twitterbot import TwitterBot
- import keys
- from random import choice
- class GrammarBot(TwitterBot):
- def bot_init(self):
- """ Initialize and configure alicebot """
- ############################
- # REQUIRED: LOGIN DETAILS! #
- ############################
- self.config['api_key'] = keys.consumer_key
- self.config['api_secret'] = keys.consumer_secret
- self.config['access_key'] = keys.access_token
- self.config['access_secret'] = keys.access_token_secret
- ######################################
- # SEMI-OPTIONAL: OTHER CONFIG STUFF! #
- ######################################
- # how often to tweet, in seconds
- self.config['tweet_interval'] = 1 * 60
- # use this to define a (min, max) random range of how often to tweet
- # e.g., self.config['tweet_interval_range'] = (5*60, 10*60) # tweets every 5-10 minutes
- self.config['tweet_interval_range'] = None
- # only reply to tweets that specifically mention the bot
- self.config['reply_direct_mention_only'] = True
- # only include bot followers (and original tweeter) in @-replies
- self.config['reply_followers_only'] = True
- # fav any tweets that mention this bot?
- self.config['autofav_mentions'] = False
- # fav any tweets containing these keywords?
- self.config['autofav_keywords'] = []
- # follow back all followers?
- self.config['autofollow'] = False
- # create a new chatterbot and load the AIML file
- self.alice = aiml.Kernel()
- self.alice.learn("german.aiml")
- def on_scheduled_tweet(self):
- """ Make a public tweet to the bot's own timeline. """
- pass
- def on_mention(self, tweet, prefix):
- """ Actions to take when a mention is received. """
- subj = ['I', 'Hannah and Joe', 'The Jacksons', 'Cats', 'The Germans']
- verbs = ['eat', 'sleep', 'run', 'watch']
- prep = ['an', 'a', 'the', 'on', 'in', 'over']
- obj = ['apple', 'tree', 'car', 'television', 'Weisswurst']
- a = random.choice(subj)
- b = random.choice(verbs)
- c = random.choice(prep)
- d = random.choice(obj)
- tweetsize = 140 - len(prefix) - 1
- try:
- # get a response from the chatterbot
- response = a + b + c + d
- # create a tweet and make sure to cut it off at 140 chars
- text = prefix + "Like this?" + response
- text = text[:140]
- # post the tweet
- self.post_tweet(text, reply_to=tweet)
- except Exception as e:
- print(e)
- def on_timeline(self, tweet, prefix):
- """ Actions to take on a timeline tweet. """
- pass
- if __name__ == '__main__':
- bot = GrammarBot()
- bot.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement