-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.py
194 lines (160 loc) · 8.34 KB
/
service.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from typing import List, Dict, Any
import pandas as pd
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
import uvicorn
from models import JobMappingGithubS2, JobMappingKaggleS1, JobMappingGithubS4, JobMappingKaggleS3, \
SearchJobRequestModel, CompanyMappingDS2, SearchCompanyRequestModel, job_col_mappings, DBMapping
from data_handlers import job_search_results, company_search_results, \
job_addition, job_addition_to_existing, delete_job_source, delete_from_existing_table, get_user_data
app = FastAPI()
templates = Jinja2Templates(directory="templates")
@app.get("/",response_class=HTMLResponse)
async def root(request: Request):
# return {"message": "Website is live. Please enter /docs to access the APIs"}
return templates.TemplateResponse("home.html",context={"request":request})
@app.post("/v1/search/jobs")
async def search_jobs(job_request: SearchJobRequestModel) -> List[Dict[str, Any]]:
query_dict = dict(job_request)
print(query_dict)
new_query = {}
for keys in query_dict.keys():
if query_dict[keys] not in ['', 0, 'string']:
new_query[keys] = query_dict[keys]
print(new_query)
return job_search_results(new_query)
@app.post("/v1/search/company")
async def search_company(company_request: SearchCompanyRequestModel) -> List[Dict[str, Any]]:
query_dict = dict(company_request)
print(query_dict)
new_query = {}
for keys in query_dict.keys():
if query_dict[keys] not in ['', 0, 'string']:
new_query[keys] = query_dict[keys]
print(new_query)
return company_search_results(new_query)
@app.post("/v1/add/new_job")
async def add_job(add_job_request: SearchJobRequestModel) -> List[Dict[str, Any]]:
query_dict = dict(add_job_request)
print(query_dict)
return job_addition(query_dict)
@app.post("/v1/add/new_job2")
async def add_job2(add_job_request: SearchJobRequestModel) -> List[Dict[str, Any]]:
query_dict = dict(add_job_request)
print(query_dict)
return job_addition(query_dict)
@app.post("/v1/add/new_job_existing_table")
async def add_job(add_job_request: SearchJobRequestModel, table: DBMapping) -> List[Dict[str, Any]]:
query_dict = dict(add_job_request)
print(query_dict)
return job_addition_to_existing(query_dict, table)
@app.post("/v1/delete/data_source")
async def delete_source(table: DBMapping) -> str:
table_name = table
return delete_job_source(table_name)
@app.post("/v1/delete/query")
async def delete_query(delete_request: SearchJobRequestModel) -> List[Dict[str, Any]]:
query_dict = dict(delete_request)
new_query = {}
for keys in query_dict.keys():
if query_dict[keys] not in ['', 0, 'string']:
new_query[keys] = query_dict[keys]
print(new_query)
return delete_from_existing_table(new_query)
@app.get("/login", response_class=HTMLResponse, include_in_schema=False)
def login_page(request: Request):
return templates.TemplateResponse("login.html", context={"request": request})
@app.get("/signup", response_class=HTMLResponse, include_in_schema=False)
def signup_page(request: Request):
return templates.TemplateResponse("signup.html", context={"request": request})
@app.get("/dashboard", response_class=HTMLResponse, include_in_schema=False)
async def dashboard(request: Request):
print("Hello")
name = request.query_params.get('name', '')
email = request.query_params.get('email', '')
user_data=get_user_data(email)[0]
# print(user_data)
location=user_data["location"]
experience=user_data["eligibility"]
return templates.TemplateResponse("user_dashboard.html", context={"request": request, "name":name, "email":email, "location":location, "experience":experience})
@app.get("/job_search", response_class=HTMLResponse, include_in_schema=False)
def jobSearch(request: Request):
return templates.TemplateResponse("JobSearch.html", context={"request": request})
@app.get("/job_search_result",response_class=HTMLResponse, include_in_schema=False)
async def search_jobs( request: Request):
new_query = {}
new_query["company_name"] = request.query_params.get('company_name', '')
new_query["title"] = request.query_params.get('title', '')
new_query["location"] = request.query_params.get('location', '')
new_query["salary"] = request.query_params.get('salary', '')
new_query["eligibility"] = request.query_params.get('eligibility', '')
new_query["description"] = request.query_params.get('description', '')
new_query["industry"] = request.query_params.get('industry', '')
new_query["link"] = request.query_params.get('link', '')
new_query["date_posted"] = request.query_params.get('date_posted', '')
new_query["employment_type"] = request.query_params.get('employment_type', '')
#print(job_search_results(new_query))
df = pd.DataFrame.from_dict(job_search_results(new_query))
html = df.to_html( index=False, classes='stocktable', table_id='result')
html = html.replace('class="dataframe ','class="')
# return templates.TemplateResponse("JobSearch.html", context={"request": request})
return templates.TemplateResponse("result.html", context={"request": request,"table":html})
@app.get("/company_search", response_class=HTMLResponse, include_in_schema=False)
def companySearch(request: Request):
return templates.TemplateResponse("CompanySearch.html", context={"request": request})
@app.get("/company_search_result", response_class=HTMLResponse, include_in_schema=False)
async def search_companies( request: Request):
new_query = {}
new_query["name"] = request.query_params.get('name', '')
new_query["domain"] = request.query_params.get('domain', '')
new_query["year_founded"] = request.query_params.get('year_founded', '')
new_query["industry"] = request.query_params.get('industry', '')
new_query["locality"] = request.query_params.get('locality', '')
new_query["country"] = request.query_params.get('country', '')
new_query["industry"] = request.query_params.get('industry', '')
new_query["linkedin_url"] = request.query_params.get('linkedin_url', '')
new_query["current_employees"] = request.query_params.get('current_employees', '')
new_query["total_employees"] = request.query_params.get('total_employees', '')
print(new_query)
#print(job_search_results(new_query))
res=company_search_results(new_query)
df = pd.DataFrame.from_dict(res)
html = df.to_html( index=False, classes='stocktable', table_id='result')
html = html.replace('class="dataframe ','class="')
if(df.empty):
return templates.TemplateResponse("result_company.html", context={"request": request})
openings_list=[]
# print(res)
# for i in range(0,len(res)):
# job_query={}
# job_query["company_name"]=res[i]["name"].capitalize()
# # print(job_query)
# openings_list.append(job_search_results(job_query))
# df2 = pd.DataFrame.from_dict(openings_list)
job_query={}
job_query["company_name"]=new_query["name"].capitalize()
df2 = pd.DataFrame.from_dict(job_search_results(job_query))
if(df2.empty):
return templates.TemplateResponse("result_company.html", context={"request": request,"company":html})
html2 = df.to_html( index=False, classes='stocktable', table_id='result2')
html2 = html.replace('class="dataframe ','class="')
return templates.TemplateResponse("result_company.html", context={"request": request,"company":html, "job":html2})
@app.get("/Recommended", response_class=HTMLResponse, include_in_schema=False)
def RecommendedSearch(request: Request):
print("Recommended Search")
email = "[email protected]"
user_data=get_user_data(email)[0]
# print(user_data)
new_query = {}
new_query['location']=user_data["location"]
new_query['eligibility']=user_data["eligibility"]
print("looking for error")
print(job_search_results(new_query))
df = pd.DataFrame.from_dict(job_search_results(new_query))
html = df.to_html( index=False, classes='stocktable', table_id='result')
html = html.replace('class="dataframe ','class="')
#return templates.TemplateResponse("JobSearch.html", context={"request": request})
return templates.TemplateResponse("result.html", context={"request": request,"table":html})
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8000)