-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcidrbot_run.py
More file actions
48 lines (40 loc) · 1.35 KB
/
cidrbot_run.py
File metadata and controls
48 lines (40 loc) · 1.35 KB
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
import logging
import datetime
import json
import os
import sys
from wxt_cidrbot.cidrbot import cidrbot
from wxt_cidrbot.git_webhook_handler import gitwebhook
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def lambda_handler(event, handle):
logger.debug('new event received: %s', str(event))
logger.debug(str(event))
logger.debug(str(handle))
start_time = datetime.datetime.now()
if "BASE_WEBHOOK_PATH" in os.environ:
webhook_path = os.getenv("BASE_WEBHOOK_PATH")
else:
logging.error("Environment variable BASE_WEBHOOK_PATH must be set")
sys.exit(1)
cidr = cidrbot()
git = gitwebhook()
# Determine the type of event and execute the correct function
if 'rawPath' in event:
if event['rawPath'] == '/github' + webhook_path:
git.webhook_request(event)
if event['rawPath'] == webhook_path:
cidr.webhook_request(event)
if event.get("Type") == "Timer":
cidr.send_timed_msg()
elif event.get("Type") == "Weekly Timer":
cidr.weekly_reminder_email()
end_time = datetime.datetime.now()
logger.debug('Script complete, total runtime {%s - %s}', end_time, start_time)
return {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": json.dumps({"testkey ": "testval"})
}