-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_app.py
71 lines (56 loc) · 2.3 KB
/
function_app.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
"""
To test locally, run the following in PowerShell:
$body = @{candidateId = 475} | ConvertTo-Json
$response = Invoke-RestMethod -Uri "http://localhost:7071/api/http_incognito" -Method Post -Body $body -ContentType "application/json"
$response
"""
import json
import logging
import os
import sys
import azure.functions as func
# Import the parse_postmeta and create_resume modules
from parse_postmeta import get_candidate_data
from create_resume import generate_resume
sys.path.insert(0, os.path.dirname(__file__))
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="http_incognito")
def http_incognito(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
try:
req_body = req.get_json()
except ValueError:
logging.error("Failed to parse request body as JSON")
return func.HttpResponse("Invalid request body", status_code=400)
logging.info(f"Received data: {req_body}")
candidate_id = req_body.get('candidateId')
if candidate_id:
try:
# Call the parse_postmeta function and pass the candidate_id
resume_data = get_candidate_data(candidate_id)
logging.info(f"Resume json: {resume_data}")
# Call the create_resume function to generate the resume document
resume_document = generate_resume(resume_data)
logging.info(f"Resume text: {resume_document}")
response = {
"version": 'Python %s\n' % sys.version.split()[0],
"output": resume_document,
"message": "Resume successfully created."
}
except Exception as e:
logging.error(f"Error in parse_postmeta: {e}")
response = {
"version": 'Python %s\n' % sys.version.split()[0],
"output": None,
# Update message to reflect the actual error
"message": f"Error: {e}",
}
else:
logging.error("Missing 'candidateId' in request body")
return func.HttpResponse("Missing 'candidateId' in request body", status_code=400)
json_response = json.dumps(response)
return func.HttpResponse(
json_response,
status_code=200,
mimetype="application/json"
)