Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ranking by view-to-subscriber ratio
import pandas as pd
def find_title(item):
title = item['snippet']['title']
return title
def find_viewcount(item, youtube_api):
video_id = item['id']['videoId']
video_statistics = youtube_api.videos().list(id=video_id, part='statistics').execute()
viewcount = int(video_statistics['items'][0]['statistics']['viewCount'])
return viewcount
def find_num_subscribers(channel_id, youtube_api):
subs_search = youtube_api.channels().list(id=channel_id, part='statistics').execute()
num_subscribers = int(subs_search['items'][0]['statistics']['subscriberCount'])
return num_subscribers
def custom_score(viewcount, subs):
ratio = viewcount / subs
score = viewcount * ratio
return score
df = pd.DataFrame(columns=('Title', 'Custom Score')
i = 1
for item in results['items']:
title = find_title(item)
viewcount = find_viewcount(item, youtube_api)
num_subs = find_num_subscribers(channel_id, youtube_api)
score = custom_score(viewcount, num_subs)
df.loc[i] = [title, score]
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.