-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremotive_jobs.py
50 lines (36 loc) · 1.47 KB
/
remotive_jobs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Description: Test the Remotive API
Author: Victor J.
Date: 8/13/2022
"""
# fetching the jobs
import requests
# converting to dictionary
import json
# for stripping the html from the job descriptions
from bs4 import BeautifulSoup
# limiting the number of pages to fetch
import time
BASE_URL = 'https://remotive.com/api/remote-jobs?search='
# ---------------------------------------------------------------------------- #
def getRemotiveJobs(search_terms):
start = time.time()
url = BASE_URL + str(search_terms)
response = requests.get(url)
if response.status_code != 200:
return {'error': f'Recieved status code {response.status_code} for remotive jobs with error {response.text}'}
else:
response_json = json.loads(response.text)
for job in response_json['jobs']:
uncleaned_description = job['description']
html_removed_description = BeautifulSoup(uncleaned_description, "lxml").text
description_encoded = html_removed_description.encode("ascii", "ignore")
description_decoded = description_encoded.decode().replace('\n', ' ').replace(' ', ' ')
job['description'] = description_decoded
print("\nFinished fetching Remotive jobs in", time.time() - start)
return response_json
# ---------------------------------------------------------------------------- #
if __name__ == "__main__":
search_terms = "front end"
jobs_json = getRemotiveJobs(search_terms)
print(jobs_json)