-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
134 lines (114 loc) · 4.07 KB
/
main.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
from fastapi import FastAPI, UploadFile, File, Request#,WebSocket
from fastapi.middleware.cors import CORSMiddleware
from modules.pdfHrefExtractor import availableScreeningProfiles
from tempfile import TemporaryDirectory
from modules.orchestratorAPI import UIPathOrchestrator,readJson
from modules.idGenerator import IDGenerator
from modules.appScript import AppScriptAPI
import config as cfg
from datetime import datetime as d
from time import time
app = FastAPI()
# origins = [
# "http://localhost:3000/*",
# "https://https://intellipick.web.app/*"
# ]
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
secrets = readJson(jsonPath=cfg.paths["uiPathSecretsPath"])
orchestrator = UIPathOrchestrator(RobotId = secrets["RobotId"],
ReleaseKey = secrets["ReleaseKey"],
MachineId = secrets["MachineId"])
idGen = IDGenerator()
appScript = AppScriptAPI(secretsPath = cfg.paths["appScriptSecrets"])
@app.get("/")
async def main():
return {"message": "Hello Gals and Boiz"}
@app.post("/file_upload")
async def upload_file(resumePdf: UploadFile = File(...)):
data = resumePdf.file.read()
idx = idGen.generate()
with TemporaryDirectory() as d: #Adding the file into a temporary storage for re-reading purposes
tmpf = d + "pdf.pdf"
with open(tmpf,"wb") as f:
f.write(data)
hrefs = availableScreeningProfiles(str(tmpf),idStr = idx,fileName=resumePdf.filename)
return hrefs
def completeRequestAndReturnResults(jobParams:dict,weights:dict=None):
if weights is None:
weights = cfg.defaultWeights
if len(jobParams) == 0:
return {
"error":True,
"jobId":"NA",
"jobResponse":"NA",
"msg":"Unfortunately our scrapping failed to locate any social links that are supported at the moment. You might want to try with some other set of files.",
"status_code": 400
}
date = d.now()
dateString = f'{date.strftime("%Y-%m-%d %H:%M:%S")}__{time()}'
print(jobParams)
jobParams = {
'jsonArgument':{
'running':False,
'dateString': dateString,
'params':jobParams,
'weights': weights
}
}
# print("New Job Params = ", jobParams)
if orchestrator.free:
response = orchestrator.startAJob(jobParams = jobParams,
folderId=secrets["folderId"],
runTimeType="Unattended")
else:
return {
"error": True,
"jobId": "NA",
"jobResponse": "NA",
"msg": "Only one Unattended Robot is allowed. Someone else is already using it :(. Please try after some time.",
"status_code":500
}
data = appScript.getMultipleSheetDataAtOnce(sheetDetails = [
{
"name":"immediateMerged",
"tag":"as_data"
},
{
"name":"imps",
"tag":"programming_data"
}
]).json()
if data["error"]:
return {**data}
payload = data["payload"]
return {**response,**payload}
@app.post("/trigger_ui_path")
async def trigger_ui_path(req:Request):
jobParams = await req.json()
result = completeRequestAndReturnResults(jobParams = jobParams["allResponses"],
weights=jobParams["weights"])
return result
# @app.websocket("/ws")
# async def websocket_endpoint(websocket: WebSocket):
# print('Accepting client connection...')
# await websocket.accept()
# while True:
# try:
# # Wait for any message from the client
# jobParams=await websocket.receive_json()
# result = completeRequestAndReturnResults(jobParams = jobParams["allResponses"],
# weights=jobParams["weights"])
# # Send message to the client
# await websocket.send_json(result)
# # print(data)
# except Exception as e:
# print('error:', e)
# break
# print('Bye..')
#https://cloud.google.com/run/docs/quickstarts/build-and-deploy/python