Spaces:
Sleeping
Sleeping
Commit
·
6b24d80
1
Parent(s):
4c11d35
Move the DB to a class
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from jobspy_indeed import indeed_get_jobs
|
|
7 |
from WelcomeToTheJungle import wtoj_get_jobs
|
8 |
from jobspy_linkedin import linkedin_get_jobs
|
9 |
from ai_manager import get_extra_information
|
10 |
-
from db import
|
11 |
|
12 |
def html_format_page(jobs : List[JobDescription]):
|
13 |
result = ["<html><head><style>.job{display: flex;width:70%;margin: 5px auto;border: 1px solid;border-radius: 5px;}.logobox{flex: 1;display: flex;align-items: center;justify-content: center;}.logo{width:100px;height:100px}h4{margin: 2px;}</style></head><body>"]
|
@@ -56,7 +56,8 @@ def search_jobs(search_term, platform):
|
|
56 |
for job in selected_jobs:
|
57 |
job.ai_result = get_extra_information(job.company, job.job_description)
|
58 |
|
59 |
-
|
|
|
60 |
|
61 |
return html_format_page(selected_jobs)
|
62 |
|
|
|
7 |
from WelcomeToTheJungle import wtoj_get_jobs
|
8 |
from jobspy_linkedin import linkedin_get_jobs
|
9 |
from ai_manager import get_extra_information
|
10 |
+
from db import Database
|
11 |
|
12 |
def html_format_page(jobs : List[JobDescription]):
|
13 |
result = ["<html><head><style>.job{display: flex;width:70%;margin: 5px auto;border: 1px solid;border-radius: 5px;}.logobox{flex: 1;display: flex;align-items: center;justify-content: center;}.logo{width:100px;height:100px}h4{margin: 2px;}</style></head><body>"]
|
|
|
56 |
for job in selected_jobs:
|
57 |
job.ai_result = get_extra_information(job.company, job.job_description)
|
58 |
|
59 |
+
db = Database()
|
60 |
+
db.add_to_db(selected_jobs)
|
61 |
|
62 |
return html_format_page(selected_jobs)
|
63 |
|
db.py
CHANGED
@@ -6,47 +6,52 @@ import json
|
|
6 |
|
7 |
REPO_ID = "jobsearch_database"
|
8 |
FILE_NAME = "db.json"
|
9 |
-
|
10 |
-
DB : List[JobDescription] = []
|
11 |
-
|
12 |
JSON_DATASET_DIR = Path("json_dataset")
|
13 |
JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
14 |
JSON_DATASET_PATH = JSON_DATASET_DIR / FILE_NAME
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
def
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
REPO_ID = "jobsearch_database"
|
8 |
FILE_NAME = "db.json"
|
|
|
|
|
|
|
9 |
JSON_DATASET_DIR = Path("json_dataset")
|
10 |
JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
11 |
JSON_DATASET_PATH = JSON_DATASET_DIR / FILE_NAME
|
12 |
|
13 |
+
class Database:
|
14 |
+
def __init__(self):
|
15 |
+
self.DB : List[JobDescription] = []
|
16 |
+
|
17 |
+
|
18 |
+
def get_current_db(self) -> List[JobDescription]:
|
19 |
+
filepath = hf_hub_download(repo_id=REPO_ID, filename=FILE_NAME, repo_type="dataset")
|
20 |
+
with open(filepath, 'r') as file:
|
21 |
+
return json.load(file)
|
22 |
+
|
23 |
+
def save_db(self, new_db):
|
24 |
+
api = HfApi()
|
25 |
+
with open(FILE_NAME, 'w') as file:
|
26 |
+
json.dump(new_db, file, indent=4)
|
27 |
+
api.upload_file(
|
28 |
+
path_or_fileobj=FILE_NAME,
|
29 |
+
path_in_repo=FILE_NAME,
|
30 |
+
repo_id=REPO_ID,
|
31 |
+
repo_type="dataset",
|
32 |
+
)
|
33 |
+
|
34 |
+
def merge_dbs(self, list1 : List[JobDescription], list2 : List[JobDescription]):
|
35 |
+
unique_urls = set()
|
36 |
+
merged_list = []
|
37 |
+
|
38 |
+
for job in list1 + list2:
|
39 |
+
if job.url not in unique_urls:
|
40 |
+
unique_urls.add(job.url)
|
41 |
+
merged_list.append(job)
|
42 |
+
|
43 |
+
return merged_list
|
44 |
+
|
45 |
+
def add_to_db(self, new_jobs : List[JobDescription]):
|
46 |
+
#Remove descriptions from the JobDescription
|
47 |
+
for job in new_jobs:
|
48 |
+
job.job_description = ""
|
49 |
+
|
50 |
+
#get current DB
|
51 |
+
current_db = self.DB
|
52 |
+
#merge
|
53 |
+
new_db = self.merge_dbs(current_db, new_jobs)
|
54 |
+
|
55 |
+
#update
|
56 |
+
self.save_db(new_db)
|
57 |
+
self.DB = new_db
|