예제 #1
0
 def random(self):
     '''
     随机获取代理地址
     :return:
     '''
     url = 'https://www.baidu.com'
     value = r.random(self.key)
     if value is None:
         self.getContent()
     proxies = {"http": "http://" + value.decode("utf-8")}
     try:
         data = requests.get(url=url,
                             headers=self.headers,
                             proxies=proxies,
                             timeout=5)
         if data.status_code is not 200:
             print('删除')
             r.delete(self.key, value)
             self.random()
         else:
             return 'http://' + value.decode("utf-8")
     except:
         print('删除')
         r.delete(self.key, value)
         self.random()
예제 #2
0
def restart(postback_payload, user_id):
    if postback_payload.endswith("yes"):
        advent.new_game(user_id)
        response = advent.respond(user_id, "no")
        smooch.send_message(user_id, response, True)
        r.delete("yesno:" + user_id)
        return True
    elif postback_payload.endswith("no"):
        r.delete("yesno:" + user_id)
        smooch.send_message(user_id, "Ok.", True)
        return True
    else:
        logging.error("Invalid postback={}".format(postback_payload))
        return False
예제 #3
0
def game_fallback(postback_payload, user_id):
    if postback_payload.endswith("yes"):
        response = advent.respond(user_id, "yes")

        # Checking if user has asked to end the game.
        if re.search("You scored \d+ out of a possible \d+ using \d+ turns.", response):
            respond(user_id, response)
            advent.new_game(user_id)
            r.set("yesno:" + user_id, "new_game")
            smooch.send_postbacks(user_id, "Do you want to play again?",
                                  [("Yes", "start_new_yes"),
                                   ("No", "start_new_no")])
            return True
        respond(user_id, response)
        r.delete("yesno:" + user_id)
        return True
    elif postback_payload.endswith("no"):
        response = advent.respond(user_id, "no")
        respond(user_id, response)
        r.delete("yesno:" + user_id)
        return True
    else:
        logging.error("Invalid postback={}".format(postback_payload))
        return False