-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsearch_jobs.py
87 lines (66 loc) · 1.88 KB
/
search_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import argparse
import json
import logging
import os
import pprint
from typing import Dict, List, Mapping
import requests
from dotenv import load_dotenv
from jobhunter import config
# import config
# Add the path to the .env file
dotenv_path = os.path.join(os.path.dirname(__file__), "..", ".env")
load_dotenv(dotenv_path)
# Get the API key from the environment variable
RAPID_API_KEY = os.environ.get("RAPID_API_KEY")
# Get the API URL from the config file
JOB_SEARCH_URL = config.JOB_SEARCH_URL
pp = pprint.PrettyPrinter(indent=4)
logging.basicConfig(level=config.LOGGING_LEVEL)
def search_jobs(
search_term: str, page: int = 1
) -> List[Dict]:
url = JOB_SEARCH_URL
querystring = {
"query": search_term,
"page": page
}
headers = {
"X-RapidAPI-Key": str(RAPID_API_KEY),
"X-RapidAPI-Host": config.JOB_SEARCH_X_RAPIDAPI_HOST,
}
try:
response = requests.get(url, headers=headers, params=querystring)
json_object = json.loads(response.text)
json_response_data = json_object.get("data")
return json_response_data
except ValueError as value_err:
logging.error(value_err)
return [{"error": value_err}]
def main(search_term, page):
results = search_jobs(
search_term=search_term, page=page
)
return results
def entrypoint():
parser = argparse.ArgumentParser(description="This searches for jobs")
parser.add_argument(
"search",
type=str,
metavar="search",
help="the term to search for, like job title",
)
parser.add_argument(
"page",
type=int,
default=1,
metavar="page",
help="the page of results, page 1, 2, 3,...etc.",
)
args = parser.parse_args()
result = main(
search_term=args.search, page=args.page
)
pp.pprint(result)
if __name__ == "__main__":
entrypoint()