Spaces:
Sleeping
Sleeping
Create job_api.py
Browse files- job_api.py +27 -0
job_api.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
def fetch_jobs(parsed):
|
| 4 |
+
api_url = "https://api.adzuna.com/v1/api/jobs/us/search/1"
|
| 5 |
+
params = {
|
| 6 |
+
"app_id": "YOUR_APP_ID",
|
| 7 |
+
"app_key": "YOUR_APP_KEY",
|
| 8 |
+
"results_per_page": 5,
|
| 9 |
+
"what": ", ".join(parsed["skills"][:5]),
|
| 10 |
+
"where": "remote",
|
| 11 |
+
"content-type": "application/json"
|
| 12 |
+
}
|
| 13 |
+
try:
|
| 14 |
+
res = requests.get(api_url, params=params)
|
| 15 |
+
data = res.json()
|
| 16 |
+
return [
|
| 17 |
+
{
|
| 18 |
+
"title": x["title"],
|
| 19 |
+
"company": x["company"]["display_name"],
|
| 20 |
+
"location": x["location"]["display_name"],
|
| 21 |
+
"salary": x.get("salary_is_predicted", "N/A"),
|
| 22 |
+
"url": x["redirect_url"]
|
| 23 |
+
}
|
| 24 |
+
for x in data.get("results", [])
|
| 25 |
+
]
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return [{"title": "No job listings found.", "company": "", "location": "", "salary": "", "url": ""}]
|