Certainly! Below is a Python program that searches for free college courses related to any topic you specify. This program uses the OER Commons API to find open educational resources licensed under Creative Commons, ensuring that the courses are free to access.
import requests
def find_free_courses(topic):
"""Find free college courses related to the given topic."""
# OER Commons API endpoint
api_url = "https://www.oercommons.org/api/v2/search"
params = {
'q': topic,
'batch_size': 20,
'filter': 'education_level:College / Upper Division|College / Lower Division',
}
response = requests.get(api_url, params=params)
if response.status_code == 200:
data = response.json()
resources = data.get('results', [])
if not resources:
print(f"No free college courses found for '{topic}'.")
return
print(f"Free college courses for '{topic}':\n")
for resource in resources:
title = resource.get('title')
description = resource.get('description') or "No description available."
url = resource.get('url')
print(f"Title: {title}\nDescription: {description}\nURL: {url}\n")
else:
print("Error fetching data from OER Commons API. Please try again later.")
if __name__ == "__main__":
topic = input("Enter a topic to search for free college courses: ")
find_free_courses(topic)
How the Program Works:
-
Imports the requests library: This library is used to make HTTP requests to the API.
-
Defines the find_free_courses function: This function accepts a topic as an argument.
-
Sets up API parameters:
q: The search query entered by the user.
batch_size: Number of results to return (you can adjust this number).
filter: Filters results to college-level courses.
-
Makes a GET request to the OER Commons API: Retrieves data in JSON format.
-
Processes the API response:
- Checks if the response status is
200 OK.
- Parses the JSON data to extract course information.
- Prints the title, description, and URL for each course found.
-
Handles errors: If the API request fails, it alerts the user.
Instructions to Run the Program:
-
Install Required Libraries:
Ensure you have the requests library installed. If not, install it using:
pip install requests
-
Save the Script:
Save the script in a file named, for example, find_free_courses.py.
-
Run the Script:
Navigate to the directory containing the script and run:
python find_free_courses.py
-
Enter a Topic:
When prompted, enter the topic you are interested in. For example:
Enter a topic to search for free college courses: Computer Science
The program will display a list of free college courses related to your topic.
Sample Output:
Enter a topic to search for free college courses: Data Science
Free college courses for 'Data Science':
Title: Data Science Ethics
Description: Explore ethical issues in data science, including privacy, bias, and transparency.
URL: https://www.oercommons.org/courses/data-science-ethics
Title: Introduction to Machine Learning
Description: Learn the basics of machine learning algorithms and their applications.
URL: https://www.oercommons.org/courses/introduction-to-machine-learning
... (additional courses)
Notes:
-
Adjust Filters as Needed: You can modify the filter parameter to refine the search results, such as targeting specific subjects or education levels.
-
API Rate Limits: Be mindful of the API's rate limits to avoid being blocked. If you're making many requests, consider adding delays or caching results.
-
Error Handling: The program includes basic error handling for failed API requests. You may enhance it to handle more specific exceptions.
Disclaimer: The availability of courses depends on the resources indexed by OER Commons. This program retrieves publicly available information and complies with the terms of use of the OER Commons API.
Feel free to customize and expand upon this script to better suit your needs, such as integrating it into a larger application or enhancing the user interface.