def main(): cupidbot, twitterstream = setup() cupidbot.login() # log_threads(cupidbot) while True: respond_to_messages(cupidbot, twitterstream) cupidbot._browser.get("http://www.google.com") # random number close to 60 (seconds) r = 60 * (1 + 0.2 * np.random.randn()) okcupid.sleep(SETTINGS.sleep_time_minutes * r)
def main(): cupidbot, twitterstream = setup() cupidbot.login() #log_threads(cupidbot) while True: respond_to_messages(cupidbot, twitterstream) cupidbot._browser.get('http://www.google.com') # random number close to 60 (seconds) r = 60 * (1 + 0.2 * np.random.randn()) okcupid.sleep(SETTINGS.sleep_time_minutes * r)
def respond_to_messages(cupidbot, twitterstream): """Respond to all of the unreplied messages on the cupidbot with an entry from the twitterstream Parameters ---------- cupidbot : okcupid.OkCupid An instance of the okcupid webdriver API, capable of interacting programmatically with the site twitterstream : twitter.Tweeterator An iterator that provides the text of tweets as a stream. Also needs to have a `pull` method asking it to load up some more tweets into its buffer """ threads = cupidbot.get_threads(["unreadMessage", "readMessage"]) logging.info("Replying to %s", threads) logging.info("number of unreplied messages: %d", len(threads)) twitterstream.pull(len(threads)) for tid in threads: log_threads(cupidbot, [tid]) thread = db.query(models.Thread).filter_by(okc_id=tid).first() target = thread.messages[-1].body get_tweet = True while get_tweet: response = twitterstream.next(target=target) try: print 'RESPONDING WITH: "%s"' % response except UnicodeEncodeError: print "Unicode error. Getting new tweet" continue sys.stdout.flush() rlist, _, _ = select([sys.stdin], [], [], PROMPT_TIMEOUT) if len(rlist) == 0: get_tweet = False else: # the user entered something, get a new tweet get_tweet = True cupidbot.reply_to_thread(tid, response, dry_run=False) # log_threads(cupidbot, [tid]) okcupid.sleep()
def respond_to_messages(cupidbot, twitterstream): """Respond to all of the unreplied messages on the cupidbot with an entry from the twitterstream Parameters ---------- cupidbot : okcupid.OkCupid An instance of the okcupid webdriver API, capable of interacting programmatically with the site twitterstream : twitter.Tweeterator An iterator that provides the text of tweets as a stream. Also needs to have a `pull` method asking it to load up some more tweets into its buffer """ threads = cupidbot.get_threads(['unreadMessage', 'readMessage']) logging.info('Replying to %s', threads) logging.info('number of unreplied messages: %d', len(threads)) twitterstream.pull(len(threads)) for tid in threads: log_threads(cupidbot, [tid]) thread = db.query(models.Thread).filter_by(okc_id=tid).first() target = thread.messages[-1].body get_tweet = True while get_tweet: response = twitterstream.next(target=target) try: print 'RESPONDING WITH: "%s"' % response except UnicodeEncodeError: print 'Unicode error. Getting new tweet' continue sys.stdout.flush() rlist, _, _ = select([sys.stdin], [], [], PROMPT_TIMEOUT) if len(rlist) == 0: get_tweet = False else: # the user entered something, get a new tweet get_tweet = True cupidbot.reply_to_thread(tid, response, dry_run=False) #log_threads(cupidbot, [tid]) okcupid.sleep()