This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
stripe.py
executable file
·82 lines (67 loc) · 1.58 KB
/
stripe.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python
# 2014 Wells Riley
import os
import web
import json
import RPi.GPIO as GPIO
import time
from threading import Thread
from time import gmtime, strftime
# Set up LED on GPIO pin 22
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(22, GPIO.OUT)
GPIO.output(22,False)
# Blink the LED 10 times
def Blink():
for i in range(0,20):
GPIO.output(22,True)
time.sleep(0.125)
GPIO.output(22,False)
time.sleep(0.125)
# Blink the LED 5 times – slowly.
def BlinkSlow():
for i in range(0,5):
GPIO.output(22,True)
time.sleep(1)
GPIO.output(22,False)
time.sleep(1)
# Blink to indicate the server is listening
Thread(target=BlinkSlow).start()
# Catch the webhook
urls = ('/.*', 'hooks')
app = web.application(urls, globals())
class hooks:
def POST(self):
data = web.data()
ip = web.ctx['ip']
# Write to the logfile
timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
f = open('/home/pi/stripe.log','a')
f.write('[' + ip + '] ' + timestamp + ': ' + data + '\n')
f.close()
try:
stripe_json = json.loads(data)
except ValueError, e:
return '200 OK'
print
print '[' + ip + '] ' + stripe_json['type']
if data_json['type'] in ['charge.succeeded']:
print
print 'dolla dolla bills, yo!'
print
Thread(target=Blink).start()
os.system("python /home/pi/gong.py 1")
else:
pass
return '200 OK'
if __name__ == '__main__':
try:
app.run()
except KeyboardInterrupt:
print
print "Exiting..."
print
GPIO.cleanup()
pigpio.stop()
app.stop()