forked from swinton/github-app-demo.py
-
Notifications
You must be signed in to change notification settings - Fork 1
/
smee.py
35 lines (25 loc) · 773 Bytes
/
smee.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
#!/usr/bin/env python
import sys
import os
import json
import requests
from sseclient import SSEClient as Client
# Allow interruption via `kill -s INT`
# https://stackoverflow.com/a/40785230
import signal; signal.signal(signal.SIGINT, signal.default_int_handler)
try:
# Connect to stream
stream = Client(os.environ['WEBHOOK_PROXY_URL'])
# Prepare session
session = requests.Session()
for event in stream:
# Parse JSON data
data = json.loads(event.data)
# Log event
print "event", event.event, data
# Deliver data to local Flask app
if event.event == 'message':
session.post('http://localhost:5000', json=data['body'])
except KeyboardInterrupt as e:
print 'Done.'
sys.exit(0)