本文整理汇总了Python中datastore.DataStore.store_channel方法的典型用法代码示例。如果您正苦于以下问题:Python DataStore.store_channel方法的具体用法?Python DataStore.store_channel怎么用?Python DataStore.store_channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datastore.DataStore
的用法示例。
在下文中一共展示了DataStore.store_channel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from datastore import DataStore [as 别名]
# 或者: from datastore.DataStore import store_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)