当前位置: 首页>>代码示例>>Python>>正文


Python DataStore.remove_channel方法代码示例

本文整理汇总了Python中datastore.DataStore.remove_channel方法的典型用法代码示例。如果您正苦于以下问题:Python DataStore.remove_channel方法的具体用法?Python DataStore.remove_channel怎么用?Python DataStore.remove_channel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在datastore.DataStore的用法示例。


在下文中一共展示了DataStore.remove_channel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from datastore import DataStore [as 别名]
# 或者: from datastore.DataStore import remove_channel [as 别名]
def main():
	"""Parse the command line arguments, expecting one of the following formats:
		-) (-i ChannelID | -u Username) (add | check | remove)
		-) check | list
	and perform the appropriate action
	"""
	parser = get_parser()
	args = parser.parse_args()

	youtube = YouTube()
	store = DataStore('%s-data.sqlite3' % sys.argv[0], 'schema.sql')

	channel = None
	if args.username is not None:
		channel = youtube.get_channel_by_username(args.username)
	elif args.id is not None:
		channel = youtube.get_channel_by_id(args.id)

	if args.action == 'add':
		store.store_channel(channel)
	elif args.action == 'remove':
		store.remove_channel(channel)
	elif args.action == 'list':
		data = []
		for item in store.get_channels():
			data.append([
				item['id'],
				item['title'],
				arrow.get(item['added_on']).humanize(),
				arrow.get(item['last_checked']).humanize()
			])

		pretty_print(['ID', 'Title', 'Added', 'Last Checked'], data)
	elif args.action == 'check':
		# If the user passed a specific channel, check for new uploads
		# otherwhise check for uploads from every previously added channel
		channels = []
		if channel is not None:
			channels.append(store.get_channel_by_id(channel['id']))
		else:
			channels = store.get_channels()

		data = []
		to_check = dict()
		for channel_item in channels:
			to_check[channel_item['id']] = channel_item['last_checked']

		uploads = youtube.get_uploads(to_check)
		for upload in uploads:
			data.append([
				upload['channel_title'],
				upload['title'],
				arrow.get(upload['published_at']).humanize(),
				'https://youtube.com/watch?v=%s' % (upload['id'], )
			])

		pretty_print(['Channel', 'Title', 'Published', 'Link'], data)

		for channel_id in to_check.keys():
			store.update_last_checked(channel_id)
开发者ID:helmi77,项目名称:youtube-checker,代码行数:62,代码来源:checker.py


注:本文中的datastore.DataStore.remove_channel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。