Esempio n. 1
0
def capture(user_id):
	logger.debug('get user info: ' + user_id)
	user = weipai_api.get_user_info(user_id)
	dbhelper.save_user(user)
	logger.debug('save user info: ' + user_id)
	if 'videos' in user and len(user['videos']) > 0:
		videos = user['videos']
		dbhelper.save_videos(user_id, videos)
		logger.debug('save user {0} latest videos: {1}'.format(user_id, len(videos)))
	dbhelper.commit()
	return user
Esempio n. 2
0
def initialize(user_id):
	user = capture(user_id)
	video_count = user['videos_count']
	logger.debug('user {0} total videos count: {1}'.format(user_id, video_count))
	if video_count and video_count > 15:
		logger.debug('user {0} total page: {1}'.format(user_id, math.ceil(video_count / 15)))
		for i in range(1, math.ceil(video_count / 15)):
			page = i + 1
			logger.debug('user {0} more videos page: {1}'.format(user_id, page))
			videos = weipai_api.get_more_videos(user_id, page)
			logger.debug('user {0} more videos count: {1}'.format(user_id, len(videos)))
			if len(videos) > 0:
				dbhelper.save_videos(user_id, videos)
	dbhelper.commit()
	captured_videos_count = dbhelper.get_videos_count(user_id)
	logger.debug('user {0} captured videos count: {1}'.format(user_id, captured_videos_count))
	dbhelper.update_uids_info(user_id, True, captured_videos_count)
	logger.debug('update user {0} infomation'.format(user_id))
	dbhelper.commit()