-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
53 lines (47 loc) · 1.45 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
from bigweb import bigweb
from tcgplayer import tcgplayer
from hareruya import hareruya
from cardkingdom import cardkingdom
import json
import sys
import logging
import traceback
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def formatOutput(output):
return {
"statusCode": 200,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Methods": "OPTIONS,GET"
},
"body": json.dumps(output)
}
def runFunction(function, event):
logging.info("Function started with input:")
logging.info(event)
searchTerm = event['pathParameters']['querystring']
try:
result = function(searchTerm)
logging.info("Function completed with output:")
logging.info(result)
except:
exception_type, exception_value, exception_traceback = sys.exc_info()
traceback_string = traceback.format_exception(exception_type, exception_value, exception_traceback)
err_msg = json.dumps({
"errorType": exception_type.__name__,
"errorMessage": str(exception_value),
"stackTrace": traceback_string
})
logging.error(err_msg)
result = 0
return formatOutput(result)
def tcg_handler(event, context):
return runFunction(tcgplayer, event)
def big_handler(event, context):
return runFunction(bigweb, event)
def har_handler(event, context):
return runFunction(hareruya, event)
def car_handler(event, context):
return runFunction(cardkingdom, event)