diff options
| author | BasherSlash@gmail.com <BasherSlash@gmail.com> | 2011-05-14 03:06:54 +0000 | 
|---|---|---|
| committer | BasherSlash@gmail.com <BasherSlash@gmail.com> | 2011-05-14 03:06:54 +0000 | 
| commit | 3fce2f3f680a75727256069385d2e473f042a708 (patch) | |
| tree | eac40750ca9ed52c08f255c66625a2b45b2ee37c | |
| parent | 30d880c110141f00f724e74293a22db3025e41f7 (diff) | |
Currently post tweet and general question also will respond to any @ mention to account 
| -rw-r--r-- | JKTwitterBot/src/thebot.py | 58 | 
1 files changed, 46 insertions, 12 deletions
| diff --git a/JKTwitterBot/src/thebot.py b/JKTwitterBot/src/thebot.py index 858bb96..a25e0e2 100644 --- a/JKTwitterBot/src/thebot.py +++ b/JKTwitterBot/src/thebot.py @@ -54,7 +54,10 @@ if __name__ == '__main__':                  lastid = f.readline()
          except IOError:
              lastid = ''
 -
 +            
 +    reader = Twitter(domain='search.twitter.com')
 +    reader.uriparts=()
 +    
      poster = Twitter(
          auth=OAuth(
              oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMER_SECRET),
 @@ -75,15 +78,46 @@ if __name__ == '__main__':          tweet = pickle.load(f)
      with open(questions_status_update_File, 'r') as f:
          question = pickle.load(f)
 +    with open(Response_File, 'r') as f:
 +        response = pickle.load(f) 
 +    count = 0 
 +    response_count = 0 
      while True:
 -        for line in range(len(tweet)):    
 -            status_update(tweet[line]) # post a status update 
 -            print tweet[line]
 -            print 'Now sleeping... \n'
 -            time.sleep(120) # set at 5min but is at 2min
 -            print question[line] 
 -            status_update(question[line])
 -            print 'Now sleeping... \n' 
 -            time.sleep(120) # set for 2min.
 -            
 -            
\ No newline at end of file +        results = reader.search(q=username, since_id=lastid)['results']
 +        for result in reversed(results):
 +            if (response_count == len(response)-1):
 +                response_count = 0
 +            asker = result['from_user']
 +            msgid = str(result['id'])
 +            incoming_text = result['text']
 +            print " <<< " + asker + ": " + incoming_text
 +            if incoming_text.lower().find(username) != 0:
 +                print '====> No response (not directed to %s)' % (username,)
 +            elif (lastid != '') and (long(msgid) <= long(lastid)):
 +                print '====> No response (%s < %s)' % (msgid, lastid)
 +            else:
 +                outgoing_text = 'RT @' + str(asker)+' '+ str(response[response_count])
 +                response_count = response_count+1 
 +                print '====> Resp = %s' % outgoing_text
 +                try:
 +                    status_update(outgoing_text)
 +                except TwitterError as e:
 +                    print '*** Twitter returned an error:\n***%s' % e
 +                else:
 +                    lastid = msgid
 +                    print 'Last id replied = ', lastid
 +                    with open(lastid_filename, 'w') as f:
 +                        f.write(lastid)
 +            time.sleep(30)         
 +        if (count == len(tweet)-1):
 +            count = 0
 +        print count 
 +        print tweet[count]
 +        status_update(tweet[count]) # post a status update
 +        print 'Now sleeping... \n'
 +        time.sleep(10) # set at 5min but is at 2min
 +        print question[count] 
 +        status_update(question[count])
 +        print 'Now sleeping... \n' 
 +        time.sleep(10) # set for 2min.
 +        count = count+1
\ No newline at end of file | 
