Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,10 +7,23 @@ import requests
|
|
| 7 |
# Initialize FastMCP agent
|
| 8 |
mcp = FastMCP("Canada Job Bank Scraper Agent")
|
| 9 |
|
|
|
|
| 10 |
@mcp.tool(name="search_jobs")
|
| 11 |
def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = None, job_type: str = None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
base_url = "https://www.jobbank.gc.ca/jobsearch/jobsearch?"
|
| 13 |
-
|
| 14 |
params = {
|
| 15 |
"searchstring": query,
|
| 16 |
"locationstring": location,
|
|
@@ -32,9 +45,9 @@ def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = N
|
|
| 32 |
response.raise_for_status()
|
| 33 |
|
| 34 |
soup = BeautifulSoup(response.text, "html.parser")
|
| 35 |
-
|
| 36 |
jobs = []
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
for card in cards[:limit]:
|
| 40 |
title_elem = card.find("a", class_="resultJobItem-title")
|
|
@@ -59,6 +72,19 @@ def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = N
|
|
| 59 |
|
| 60 |
|
| 61 |
def search_jobs_ui(query, location, limit=10, salary=None, job_type=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
result = search_jobs_tool(query, location, limit, salary, job_type)
|
| 63 |
|
| 64 |
if "error" in result:
|
|
@@ -86,7 +112,7 @@ app = gr.Interface(
|
|
| 86 |
gr.Textbox(label="Job Type (optional, ignored)")
|
| 87 |
],
|
| 88 |
outputs="markdown",
|
| 89 |
-
title="Canada Job Bank Job Search (
|
| 90 |
description="Search jobs by scraping Canada Job Bank using requests and BeautifulSoup."
|
| 91 |
)
|
| 92 |
|
|
|
|
| 7 |
# Initialize FastMCP agent
|
| 8 |
mcp = FastMCP("Canada Job Bank Scraper Agent")
|
| 9 |
|
| 10 |
+
|
| 11 |
@mcp.tool(name="search_jobs")
|
| 12 |
def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = None, job_type: str = None):
|
| 13 |
+
"""
|
| 14 |
+
Scrape job listings from the Canada Job Bank website based on a search query and location.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
query (str): Job title or keyword to search for.
|
| 18 |
+
location (str): Location to filter jobs.
|
| 19 |
+
limit (int): Maximum number of job results to return (default: 10).
|
| 20 |
+
salary (str, optional): Ignored in this scraper but included for future API compatibility.
|
| 21 |
+
job_type (str, optional): Ignored in this scraper but included for future API compatibility.
|
| 22 |
+
|
| 23 |
+
Returns:
|
| 24 |
+
dict: A dictionary with a list of job listings or an error message.
|
| 25 |
+
"""
|
| 26 |
base_url = "https://www.jobbank.gc.ca/jobsearch/jobsearch?"
|
|
|
|
| 27 |
params = {
|
| 28 |
"searchstring": query,
|
| 29 |
"locationstring": location,
|
|
|
|
| 45 |
response.raise_for_status()
|
| 46 |
|
| 47 |
soup = BeautifulSoup(response.text, "html.parser")
|
|
|
|
| 48 |
jobs = []
|
| 49 |
+
|
| 50 |
+
cards = soup.find_all("article", class_="resultJobItem")
|
| 51 |
|
| 52 |
for card in cards[:limit]:
|
| 53 |
title_elem = card.find("a", class_="resultJobItem-title")
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
def search_jobs_ui(query, location, limit=10, salary=None, job_type=None):
|
| 75 |
+
"""
|
| 76 |
+
Interface function for displaying job search results in markdown format.
|
| 77 |
+
|
| 78 |
+
Args:
|
| 79 |
+
query (str): Job title or keyword.
|
| 80 |
+
location (str): Location to search in.
|
| 81 |
+
limit (int): Number of results to return.
|
| 82 |
+
salary (str, optional): Placeholder argument (not used).
|
| 83 |
+
job_type (str, optional): Placeholder argument (not used).
|
| 84 |
+
|
| 85 |
+
Returns:
|
| 86 |
+
str: Markdown-formatted job listings or error message.
|
| 87 |
+
"""
|
| 88 |
result = search_jobs_tool(query, location, limit, salary, job_type)
|
| 89 |
|
| 90 |
if "error" in result:
|
|
|
|
| 112 |
gr.Textbox(label="Job Type (optional, ignored)")
|
| 113 |
],
|
| 114 |
outputs="markdown",
|
| 115 |
+
title="Canada Job Bank Job Search (requests & BeautifulSoup) + FastMCP",
|
| 116 |
description="Search jobs by scraping Canada Job Bank using requests and BeautifulSoup."
|
| 117 |
)
|
| 118 |
|