Skip to content

Commit 1551b92

Browse files
authored
Create main.py
1 parent 6a91c48 commit 1551b92

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

NY_Tower_Light/lambda/main.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import paho.mqtt.publish as publish
2+
import time
3+
4+
AIO_USERNAME = 'YOURUSERNAMEHERE'
5+
AIO_KEY = 'YOURKEYHERE'
6+
7+
AIO_TOPIC = AIO_USERNAME + '/feeds/redlight'
8+
AIO_YELLOWTOPIC = AIO_USERNAME + '/feeds/yellowlight'
9+
AIO_GREENTOPIC = AIO_USERNAME + '/feeds/greenlight'
10+
11+
def webhook_handler(event, context):
12+
print('Starting webhook handler!')
13+
action = event.get('action')
14+
print('Issue action: {0}'.format(action))
15+
auth = {'username': AIO_USERNAME, 'password': AIO_KEY}
16+
17+
# for issues opened & closed
18+
if action == 'closed':
19+
publish.single(AIO_TOPIC, payload='OFF', hostname='io.adafruit.com', auth=auth)
20+
elif action in ('opened', 'reopened'):
21+
publish.single(AIO_TOPIC, payload='ON', hostname='io.adafruit.com', auth=auth)
22+
# starring & watching
23+
elif action == 'started':
24+
publish.single(AIO_YELLOWTOPIC, payload='ON', hostname='io.adafruit.com', auth=auth)
25+
time.sleep(1)
26+
publish.single(AIO_YELLOWTOPIC, payload='OFF', hostname='io.adafruit.com', auth=auth)
27+
# look for pushes
28+
elif "commits" in event:
29+
publish.single(AIO_GREENTOPIC, payload='ON', hostname='io.adafruit.com', auth=auth)
30+
time.sleep(1)
31+
publish.single(AIO_GREENTOPIC, payload='OFF', hostname='io.adafruit.com', auth=auth)
32+
33+
return 'OK'
34+
35+
36+
if __name__ == '__main__':
37+
webhook_handler({'action': 'started'}, {})

0 commit comments

Comments
 (0)