|
1 | 1 | """ eas/lookup init file """ |
| 2 | + |
2 | 3 | import os |
3 | 4 | import json |
4 | 5 | import logging |
5 | 6 | import requests |
6 | 7 | import azure.functions as func |
7 | 8 | from shared_code.common import func_json_response |
8 | 9 |
|
| 10 | + |
9 | 11 | def main(req: func.HttpRequest) -> func.HttpResponse: |
10 | | - """ main function for eas/lookup """ |
| 12 | + """main function for eas/lookup""" |
11 | 13 |
|
12 | | - logging.info('EAS Lookup processed a request.') |
| 14 | + logging.info("EAS Lookup processed a request.") |
13 | 15 |
|
14 | 16 | try: |
15 | | - params = req.params.copy() |
16 | | - if 'search' in params: |
17 | | - params['$where'] = \ |
18 | | - "address like upper('{}%') AND parcel_number IS NOT NULL"\ |
19 | | - .format(params['search']) |
20 | | - del params['search'] |
| 17 | + params = req.params.copy() |
| 18 | + if "search" in params: |
| 19 | + search_param = params["search"] |
| 20 | + params["$where"] = ( |
| 21 | + f"address like upper('{search_param}%') AND parcel_number IS NOT NULL" |
| 22 | + ) |
| 23 | + del params["search"] |
21 | 24 |
|
22 | 25 | response = requests.get( |
23 | | - os.getenv('EAS_API_URL'), |
| 26 | + os.getenv("EAS_API_URL"), |
24 | 27 | params=params, |
25 | | - headers={'X-App-Token': os.getenv('ADDRESS_SVC_APP_TOKEN')} |
| 28 | + headers={"X-App-Token": os.getenv("ADDRESS_SVC_APP_TOKEN")}, |
| 29 | + timeout=600, |
26 | 30 | ) |
27 | 31 |
|
| 32 | + cache_max_age = os.getenv("ADDRESS_SVC_CACHE_MAX_AGE") |
28 | 33 | headers = { |
29 | | - "Cache-Control": "s-maxage=1, stale-while-revalidate, max-age={}"\ |
30 | | - .format(os.getenv('ADDRESS_SVC_CACHE_MAX_AGE')), |
31 | | - "Access-Control-Allow-Origin": "*" |
| 34 | + "Cache-Control": f"s-maxage=1, stale-while-revalidate, max-age={cache_max_age}", |
| 35 | + "Access-Control-Allow-Origin": "*", |
32 | 36 | } |
33 | 37 |
|
34 | 38 | return func_json_response(response, headers) |
35 | 39 |
|
36 | | - #pylint: disable=broad-except |
| 40 | + # pylint: disable=broad-except |
37 | 41 | except Exception as err: |
38 | 42 | logging.error("EAS Lookup error occurred: %s", err) |
39 | | - return func.HttpResponse(f"This endpoint encountered an error. {err}", status_code=500) |
| 43 | + return func.HttpResponse( |
| 44 | + f"This endpoint encountered an error. {err}", status_code=500 |
| 45 | + ) |
0 commit comments