Skip to content

Instantly share code, notes, and snippets.

@chris-lovejoy
Created June 17, 2020 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-lovejoy/43c698288b37807d3d5e7cf202e7e2b1 to your computer and use it in GitHub Desktop.
Save chris-lovejoy/43c698288b37807d3d5e7cf202e7e2b1 to your computer and use it in GitHub Desktop.
including date published in model
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