Last active
November 21, 2020 21:42
-
-
Save chris-lovejoy/59c15e35cafccc49a076e6d239ddf657 to your computer and use it in GitHub Desktop.
Restricting search period
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
# Function to create string for search start date | |
def get_start_date_string(search_period_days): | |
"""Returns string for date at start of search period.""" | |
search_start_date = datetime.today() – timedelta(search_period_days) | |
date_string = datetime(year=search_start_date.year,month=search_start_date.month, | |
day=search_start_date.day).strftime(‘%Y-%m-%dT%H:%M:%SZ’) | |
return date_string | |
# Creating date string and executing search | |
date_string = get_start_date_string(7) | |
results = youtube_api.search().list(q=search_terms, part=’snippet’, | |
type=’video’, order=’viewCount’, maxResults=50, | |
publishedAfter=date_string).execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment