Create main.py
This commit is contained in:
parent
6a91c4813b
commit
1551b92e7b
1 changed files with 37 additions and 0 deletions
37
NY_Tower_Light/lambda/main.py
Normal file
37
NY_Tower_Light/lambda/main.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import paho.mqtt.publish as publish
|
||||
import time
|
||||
|
||||
AIO_USERNAME = 'YOURUSERNAMEHERE'
|
||||
AIO_KEY = 'YOURKEYHERE'
|
||||
|
||||
AIO_TOPIC = AIO_USERNAME + '/feeds/redlight'
|
||||
AIO_YELLOWTOPIC = AIO_USERNAME + '/feeds/yellowlight'
|
||||
AIO_GREENTOPIC = AIO_USERNAME + '/feeds/greenlight'
|
||||
|
||||
def webhook_handler(event, context):
|
||||
print('Starting webhook handler!')
|
||||
action = event.get('action')
|
||||
print('Issue action: {0}'.format(action))
|
||||
auth = {'username': AIO_USERNAME, 'password': AIO_KEY}
|
||||
|
||||
# for issues opened & closed
|
||||
if action == 'closed':
|
||||
publish.single(AIO_TOPIC, payload='OFF', hostname='io.adafruit.com', auth=auth)
|
||||
elif action in ('opened', 'reopened'):
|
||||
publish.single(AIO_TOPIC, payload='ON', hostname='io.adafruit.com', auth=auth)
|
||||
# starring & watching
|
||||
elif action == 'started':
|
||||
publish.single(AIO_YELLOWTOPIC, payload='ON', hostname='io.adafruit.com', auth=auth)
|
||||
time.sleep(1)
|
||||
publish.single(AIO_YELLOWTOPIC, payload='OFF', hostname='io.adafruit.com', auth=auth)
|
||||
# look for pushes
|
||||
elif "commits" in event:
|
||||
publish.single(AIO_GREENTOPIC, payload='ON', hostname='io.adafruit.com', auth=auth)
|
||||
time.sleep(1)
|
||||
publish.single(AIO_GREENTOPIC, payload='OFF', hostname='io.adafruit.com', auth=auth)
|
||||
|
||||
return 'OK'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
webhook_handler({'action': 'started'}, {})
|
||||
Loading…
Reference in a new issue