summaryrefslogtreecommitdiff
path: root/JKTwitterBot/src
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-05-23 21:18:02 +0000
committerJesse Morgan <jesse@jesterpm.net>2011-05-23 21:18:02 +0000
commitcb9abe4a21c4a4adb75127fc859d9ff1283bce16 (patch)
tree7e6e0b13086f431752954a417f02dd83e92f8ca2 /JKTwitterBot/src
parentc169275c9ae11d0ea1cfd795975127878fbbb47f (diff)
Added random usage of doctor. Made the bot sleep from midnight to 6am.
Diffstat (limited to 'JKTwitterBot/src')
-rw-r--r--JKTwitterBot/src/thebot.py18
1 files 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()