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
def find_jobs_from(website, job_title, location, desired_characs, filename="results.xls"): | |
""" | |
This function extracts all the desired characteristics of all new job postings | |
of the title and location specified and returns them in single file. | |
The arguments it takes are: | |
- Website: to specify which website to search (options: 'Indeed' or 'CWjobs') | |
- Job_title | |
- Location | |
- Desired_characs: this is a list of the job characteristics of interest, | |
from titles, companies, links and date_listed. |
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
# Call the YouTube API | |
api_key = ‘AIzpSyAq3L9DiPK0KxrGBbdY7wNN7kfPbm_hsPg’ # Enter your own API key – this one won’t work | |
youtube_api = build(‘youtube’, ‘v3’, developerKey = api_key) | |
results = youtube_api.search().list(q=search_terms, part=’snippet’, type=’video’, | |
order=’viewCount’, maxResults=50).execute() |
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
publishedAt = results[‘items’][0][‘snippet’][‘publishedAt’] |
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 calculate view-to-sub ratio | |
def view_to_sub_ratio(viewcount, num_subscribers): | |
if num_subscribers == 0: | |
return 0 | |
else: | |
ratio = viewcount / num_subscribers | |
return ratio |
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) |
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
# Adding days since published into custom score | |
def custom_score(viewcount, ratio, days_since_published): | |
if ratio > 5: | |
ratio = 5 | |
score = (viewcount * ratio) / days_since_published | |
return score | |
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
# Calculating ratio while removing edge cases (of low views or low subscribers) | |
def custom_score(viewcount, ratio, days_since_published): | |
ratio = min(ratio, 5) | |
score = (viewcount * ratio) | |
return score |
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 apiclient.discovery import build | |
api_key='AIzaKyAq3L9BiVO0PXrGBhhY0cNN9fkPmm_BsPg' # (not a real API key) | |
youtube_api = build('youtube','v3', developerKey=api_key) | |
# Search videos | |
video_search_results = youtube_api.search().list(q='productivity', part='snippet', type='video', | |
order='viewCount', maxResults=50).execute() | |
# Search channels |
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
def make_job_search(job_title, location, driver): | |
driver.get('https://www.cwjobs.co.uk/') | |
# Select the job box | |
job_title_box = driver.find_element_by_name('Keywords') | |
# Send job information | |
job_title_box.send_keys(job_title) | |
# Selection location box |
OlderNewer