From cb9abe4a21c4a4adb75127fc859d9ff1283bce16 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Mon, 23 May 2011 21:18:02 +0000 Subject: Added random usage of doctor. Made the bot sleep from midnight to 6am. --- JKTwitterBot/src/thebot.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/JKTwitterBot/src/thebot.py b/JKTwitterBot/src/thebot.py index 5152490..3a30d3c 100644 --- a/JKTwitterBot/src/thebot.py +++ b/JKTwitterBot/src/thebot.py @@ -7,6 +7,8 @@ http://blog.vivekhaldar.com/post/2830035130/how-to-write-a-twitter-bot-in-python Modified by: Karl, Jesse ''' +from datetime import datetime +from random import random from twitter.api import Twitter, TwitterError from twitter.oauth import OAuth, read_token_file from optparse import OptionParser @@ -73,7 +75,8 @@ def reply_to_tweets(): print '====> No response (%s < %s)' % (msgid, lastid) else: # Found a tweet directed to us. - usedoctor = True + # Should we use Eliza? + usedoctor = random() > 0.33 if usedoctor: doctor_response = doctor.respond(incoming_text.strip()) @@ -197,10 +200,17 @@ if __name__ == '__main__': doctor = eliza.eliza() # commented out so all friends are not added - #for friend in friends: # adds all friends from friends.txt - # follow_user(friend) + #for friend in friends: # adds all friends from friends.txt + # follow_user(friend) while True: + # We sleep between midnight at 6 am. + hour = datetime.now().hour + if hour < 6: + # Sleep until 6 am. + time.sleep((6 - hour) * 3600) + + # Reply to tweets directed to us reply_to_tweets() @@ -221,4 +231,4 @@ if __name__ == '__main__': print 'Now sleeping... \n' time.sleep(1) # set for 2min. - ask_questions() \ No newline at end of file + ask_questions() -- cgit v1.2.3