本文整理汇总了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(