本文整理汇总了Python中pick.pick方法的典型用法代码示例。如果您正苦于以下问题:Python pick.pick方法的具体用法?Python pick.pick怎么用?Python pick.pick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pick
的用法示例。
在下文中一共展示了pick.pick方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove
# 需要导入模块: import pick [as 别名]
# 或者: from pick import pick [as 别名]
def remove(self, jarvis, s):
data = self.get_data(jarvis)
if len(data) == 0:
jarvis.say("Nothing to remove!")
return
if s.startswith("everything") or s.startswith("all"):
for entry in data:
self.clean_up_entry(jarvis, entry)
data = []
self.save_data(jarvis, data)
jarvis.say("ok")
return
# open selection menu
ask_str = []
for entry in data:
ask_str.append(self.format(jarvis, entry))
title = 'Please choose task to remove (select with space)'
selected = pick(ask_str, title, multi_select=True)
selected = [entry[1] for entry in selected]
new_data = []
for index, entry in enumerate(data):
entry = data[index]
if index not in selected:
new_data.append(entry)
else:
self.clean_up_entry(jarvis, entry)
self.save_data(jarvis, new_data)
示例2: select_one_remind
# 需要导入模块: import pick [as 别名]
# 或者: from pick import pick [as 别名]
def select_one_remind(self, jarvis):
data = self.get_data(jarvis)
ask_str = []
for entry in data:
ask_str.append(self.format(jarvis, entry))
if len(ask_str) == 0:
return None
title = 'Please choose from todo list:'
_, index = pick(ask_str, title)
return data[index]
示例3: choose
# 需要导入模块: import pick [as 别名]
# 或者: from pick import pick [as 别名]
def choose(choices, title, multi=False, min_count=1, custom=False):
'''Elect one element among a collection
You can also allow tht user to enter a custom value
'''
sep = '=' * ((78 - len(title)) // 2)
title = f'{sep} {title} {sep}'
text = [title]
if multi:
plural = 's' if min_count > 1 else ''
text += MULTI_SELECT_CONTROLS.split('\n')
text.append(f"Choose {min_count} item{plural} or more from the list below then validate.")
else:
min_count = 1
text += SINGLE_SELECT_CONTROLS.split('\n')
text.append(f"Choose exactly one item from the list below then validate.")
selection = pick(choices, '\n'.join(text), multi_select=multi, min_selection_count=min_count)
if isinstance(selection, list):
selection = [item[0] for item in selection]
else:
selection = selection[0]
if custom:
while True:
selection_str = '\n - '.join(selection)
prompt = f"Do you want to add a custom value to current selection: \n - {selection_str}\nEnter your answer"
if confirm(prompt) == Answer.NO:
break
selection.append(readline("Enter a custom value", empty=False))
return selection
示例4: promptForPublicChannels
# 需要导入模块: import pick [as 别名]
# 或者: from pick import pick [as 别名]
def promptForPublicChannels(channels):
channelNames = [channel['name'] for channel in channels]
selectedChannels = pick(channelNames, 'Select the Public Channels you want to export:', multi_select=True)
return [channels[index] for channelName, index in selectedChannels]
# fetch and write history for all public channels
示例5: promptForDirectMessages
# 需要导入模块: import pick [as 别名]
# 或者: from pick import pick [as 别名]
def promptForDirectMessages(dms):
dmNames = [userNamesById.get(dm['user'], dm['user'] + " (name unknown)") for dm in dms]
selectedDms = pick(dmNames, 'Select the 1:1 DMs you want to export:', multi_select=True)
return [dms[index] for dmName, index in selectedDms]
# fetch and write history for all direct message conversations
# also known as IMs in the slack API.
示例6: promptForGroups
# 需要导入模块: import pick [as 别名]
# 或者: from pick import pick [as 别名]
def promptForGroups(groups):
groupNames = [group['name'] for group in groups]
selectedGroups = pick(groupNames, 'Select the Private Channels and Group DMs you want to export:', multi_select=True)
return [groups[index] for groupName, index in selectedGroups]
# fetch and write history for specific private channel
# also known as groups in the slack API.
示例7: run
# 需要导入模块: import pick [as 别名]
# 或者: from pick import pick [as 别名]
def run(self):
daily_recommend_infos = self.getdailyrecommend()
keys, values = list(daily_recommend_infos.keys()), list(daily_recommend_infos.values())
title = '你的网易云每日歌曲推荐如下:'
options = [v[0] for v in values]
while True:
option, index = pick(options, title, indicator='=>')
self.downloadSong(keys[index], option, values[index][1])
try:
os.system('cls')
except:
os.system('clear')
示例8: download_all
# 需要导入模块: import pick [as 别名]
# 或者: from pick import pick [as 别名]
def download_all(self):
if self.setup_credential:
sys.stdout.write(">> I'm gonna assume you are responsible enough to had "
"finished logged in by now ;)\n")
else:
sys.stdout.write('>> Logging into "{0}"... '.format(self._course.url))
sys.stdout.flush()
self.login()
sys.stdout.write('>> Retrieving echo360 Course Info... ')
sys.stdout.flush()
videos = self._course.get_videos().videos
print('Done!')
# change the output directory to be inside a folder named after the course
self._output_dir = os.path.join(self._output_dir,
'{0}'.format(self._course.nice_name).strip())
# replace invalid character for folder
self.regex_replace_invalid.sub('_', self._output_dir)
filtered_videos = [
video for video in videos if self._in_date_range(video.date)
]
videos_to_be_download = []
for video in reversed(filtered_videos): # reverse so we download newest first
lecture_number = self._find_pos(videos, video)
# Sometimes a video could have multiple part. This special method returns a
# generator where: (i) if it's a multi-part video it will contains multiple
# videos and (ii) if it is NOT a multi-part video, it will just
# returns itself
sub_videos = video.get_all_parts()
for sub_i, sub_video in reversed(list(enumerate(sub_videos))):
sub_lecture_num = lecture_number + 1
# use a friendly way to name sub-part lectures
if len(sub_videos) > 1:
sub_lecture_num = "{}.{}".format(sub_lecture_num, sub_i + 1)
title = "Lecture {} [{}]".format(sub_lecture_num, sub_video.title)
filename = self._get_filename(self._course.course_id, sub_video.date,
title)
videos_to_be_download.append((filename, sub_video))
if self.interactive_mode:
title = "Select video(s) to be downloaded (SPACE to mark, ENTER to continue):"
selected = pick([v[0] for v in videos_to_be_download], title,
multi_select=True, min_selection_count=1)
videos_to_be_download = [videos_to_be_download[s[1]] for s in selected]
print('=' * 60)
print(' Course: {0}'.format(self._course.nice_name))
print(' Total videos to download: {0} out of {1}'.format(
len(videos_to_be_download), len(videos)))
print('=' * 60)
downloaded_videos = []
for filename, video in videos_to_be_download:
if video.url is False:
print(">> Skipping Lecture '{0}' as it says it does "
"not contain any video.".format(filename))
else:
if video.download(self._output_dir, filename):
downloaded_videos.insert(0, filename)
print(self.success_msg(self._course.course_name, downloaded_videos))
self._driver.close()