Created
June 17, 2020 15:30
-
-
Save chris-lovejoy/43c698288b37807d3d5e7cf202e7e2b1 to your computer and use it in GitHub Desktop.
including date published in model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
# creating variable for time one week ago | |
today_date = datetime.today() | |
one_week_ago_date = today_date - timedelta(7) | |
one_week_ago_string = datetime(year=one_week_ago_date.year,month=one_week_ago_date.month, | |
day=one_week_ago_date.day).strftime('%Y-%m-%dT%H:%M:%SZ') | |
# updating the search by adding 'publishedAfter' | |
results = youtube.search().list(q='coding', part='snippet', type='video', | |
order='viewCount', maxResults=100, publishedAfter=one_week_ago_string).execute() | |
# incorporating ratio limit and days since published into final custom score: | |
def custom_score(viewcount, ratio, days_since_published): | |
if ratio > 5: | |
ratio = 5 | |
score = (viewcount * ratio) / days_since_published | |
return score |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment