本文整理汇总了Python中dataset.Dataset.list_files方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.list_files方法的具体用法?Python Dataset.list_files怎么用?Python Dataset.list_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.list_files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AudioBot
# 需要导入模块: from dataset import Dataset [as 别名]
# 或者: from dataset.Dataset import list_files [as 别名]
class AudioBot(telebot.TeleBot):
def __init__(self, token, description_file):
super(AudioBot, self).__init__(token, threaded=False)
with open(description_file, encoding="utf-8") as fp:
description = json.load(fp)
self.mention_words = set(description['mention_words'])
self.dataset = Dataset(description_file)
def audio_list(self, msg):
logger.info("%s: sending phrase list to user %s" % (msg.text, user_log_string(msg)))
text = ["Phrase list (use '/say ID' to choose phrase):"]
for i, title in self.dataset.list_files():
text.append("*[%2d]* _%s_" % (i, title))
self.reply_to(msg, "\n".join(text), parse_mode="Markdown")
def top_phrases(self, msg):
logger.info("%s: sending top phrases to user %s" % (msg.text, user_log_string(msg)))
lines = ["Top phrases (use '/say ID' to choose phrase):"]
for audio_id, count in self.dataset.top_phrases.most_common(5):
lines.append(
"*[%2d]* _%s_ (%d reproductions)" % (audio_id, self.dataset.get_audio_data(audio_id)['title'], count))
self.reply_to(msg, "\n".join(lines), parse_mode="Markdown")
def send_phrase(self, msg, audio_id):
if 0 <= audio_id < len(self.dataset.data_keys):
audio, duration = self.dataset.get_phrase(audio_id)
logger.info("%s: sending phrase #%d to user %s" % (msg.text, audio_id, user_log_string(msg)))
self.send_audio(msg.chat.id, audio, duration)
else:
bot.send_random_phrase(msg)
def send_random_phrase(self, msg):
logger.info("%s: sending random phrase to user %s" % (msg.text, user_log_string(msg)))
audio, duration = self.dataset.random_phrase()
self.send_audio(msg.chat.id, audio, duration)
def search_mentions(self, msg):
msg_plain = sanitize_string(msg.text)
msg_words = set(msg_plain.split())
if not self.mention_words.intersection(msg_words):
return
logger.info("mention: responding to user %s" % user_log_string(msg))
audio, duration = self.dataset.random_phrase(msg_words)
self.send_audio(msg.chat.id, audio, duration)