當前位置: 首頁>>代碼示例>>Python>>正文


Python Markov.tell_a_story方法代碼示例

本文整理匯總了Python中markov.Markov.tell_a_story方法的典型用法代碼示例。如果您正苦於以下問題:Python Markov.tell_a_story方法的具體用法?Python Markov.tell_a_story怎麽用?Python Markov.tell_a_story使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在markov.Markov的用法示例。


在下文中一共展示了Markov.tell_a_story方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SparkleBot

# 需要導入模塊: from markov import Markov [as 別名]
# 或者: from markov.Markov import tell_a_story [as 別名]

#.........這裏部分代碼省略.........
    def do_greeting(self, event):
        '''Respond to a user's greeting'''
        requestor_name = event.data.get("user_name")
        room_id = event.data.get("room_id")
        message = "Hello {}".format(requestor_name)
        self.post_result(room_id, message)

    def do_welcome_response(self, event):
        '''Respond to a user's thanks'''
        requestor_name = event.data.get("user_name")
        room_id = event.data.get("room_id")
        message = "You are welcome, {}".format(requestor_name)
        self.post_result(room_id, message)

    def do_help(self, event, event_keywords):
        '''Posts a help message to the user'''
        requestor_name = event.data.get("user_name")
        room_id = event.data.get("room_id")
        build_response = '{}, here is what I can do: '.format(requestor_name)
        for iteration, key in enumerate(event_keywords.keys()):
            build_response += ' {}. {} {} {} '.format(
                iteration + 1, 
                self.name, 
                key, 
                ' '.join(event_keywords[key]))
        self.post_result(room_id, build_response)

    def do_story(self, event):
        '''Creates a story using the Markov chain functions'''
        requestor_name = event.data.get("user_name")
        room_id = event.data.get("room_id")
        message = "Sure {}. Here is your story, a la Lewis Carrol. {}".format(
            requestor_name,
            self.marky.tell_a_story())
        self.post_result(room_id, message)

    def do_weather(self, event):
        '''Parse and handle the weather requested event'''
        msg_data = event.data.get("data")
        requestor_name = event.data.get("user_name")
        room_id = event.data.get("room_id")
        pattern = "^(.*)\s(.*)\s(\d*)"
        groups = re.findall(pattern, msg_data)
        location = groups[0][2]
        weather_response = WeatherAPI.get_weather(self.api_key, location)

        # Parsing for OpenWeatherMap
        # pp = pprint.PrettyPrinter()
        # pp.pprint(weather_response)
        # wr_city = weather_response["name"]
        # wr_main = weather_response["main"]
        # wr_main_temp = wr_main["temp"]
        # wr_weather = weather_response["weather"][0]
        # wr_weather_desc = wr_weather["description"]
        # wr_main_temp_f = (wr_main_temp * (9/5.0)) - 459.67

        # Parsing for Wunderground
        # pp = pprint.PrettyPrinter()
        # wr = weather_response["current_observation"]
        # pp.pprint(wr)
        wr_city = weather_response["current_observation"]["display_location"]["city"]
        wr_main_temp_f = weather_response["current_observation"]["temperature_string"]
        wr_weather_desc = weather_response["current_observation"]["weather"].lower()

        # Create the response payload
        message = "{}, {} is {} and is {}".format(
開發者ID:nija,項目名稱:hb-chatty,代碼行數:70,代碼來源:listener.py


注:本文中的markov.Markov.tell_a_story方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。