This script provides a "Career Inspiration Test" that dynamically suggests career paths based on user input. It leverages the SERP (Search Engine Results Page) API to retrieve career-related information from Google, filtering out ad or sponsored content to provide only relevant search results. The program begins by loading environment variables, particularly the SERP API key, and prompts the user with three questions about their interests, skills, and preferred work style. Using these inputs, it constructs a search query, fetches results from the SERP API, and displays a filtered list of career suggestions.
fetch_career_suggestions(query)
Purpose: Retrieves career suggestions based on the provided search query using the SERP API.
Parameters:
query (str): A search query constructed from user inputs about interests, skills, and work style.
Functionality:
Constructs the API request URL with parameters to exclude ads and specify the number of results.
Sends a GET request to the SERP API.
Checks if the response status is 200 (successful).
Parses the JSON response to extract organic search results.
Filters out any results that contain indicators of ads (e.g., "ad" in the link or "sponsored" in the title).
Returns a list of filtered organic results.
If the API call fails, prints an error message and returns an empty list.
career_test()
Purpose: Conducts an interactive career inspiration test for the user.
Functionality:
Displays a welcome message.
Prompts the user for input on three open-ended questions regarding their interests, skills, and preferred work environment.
Constructs a search query based on user responses.
Calls fetch_career_suggestions with the constructed query to retrieve career ideas.
Formats and prints the titles, snippets, and links of the returned career suggestions.
If no suggestions are found, prompts the user to try different inputs.
Execution: This function is invoked when the script is run directly, making it the entry point for user interaction.
Overview
This script provides a "Career Inspiration Test" that dynamically suggests career paths based on user input. It leverages the SERP (Search Engine Results Page) API to retrieve career-related information from Google, filtering out ad or sponsored content to provide only relevant search results. The program begins by loading environment variables, particularly the SERP API key, and prompts the user with three questions about their interests, skills, and preferred work style. Using these inputs, it constructs a search query, fetches results from the SERP API, and displays a filtered list of career suggestions.
fetch_career_suggestions(query)
query
(str): A search query constructed from user inputs about interests, skills, and work style.career_test()
fetch_career_suggestions
with the constructed query to retrieve career ideas.Demo