-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.py
More file actions
37 lines (25 loc) · 770 Bytes
/
handler.py
File metadata and controls
37 lines (25 loc) · 770 Bytes
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
import os
import json
from uszipcode import SearchEngine
def get(event, context):
try:
req_zipcode = event['pathParameters']['id']
zipcode_db_dir = os.path.join(os.path.dirname(__file__), ".uszipcode")
search = SearchEngine(simple_zipcode=True, db_file_dir=zipcode_db_dir)
zipcode = search.by_zipcode(req_zipcode)
search.close()
if zipcode.to_dict()['zipcode'] is not None:
rlt = zipcode.to_dict()
print(rlt)
else:
rlt = ''
statusCode = 200
except Exception as e:
print('[Error] ' + str(e))
statusCode = 400
rlt = ''
response = {
"statusCode": statusCode,
"body": json.dumps(rlt)
}
return response