|
#!/usr/bin/env python |
|
import sys |
|
|
|
print 'starting...' |
|
|
|
from twython import Twython |
|
from twython import TwythonError |
|
|
|
import RPi.GPIO as GPIO |
|
import time |
|
import pygame |
|
import random |
|
|
|
CONSUMER_KEY = '---- API key here ----' |
|
CONSUMER_SECRET = '---- API secret here ----' |
|
ACCESS_KEY = '---- Access token here ----' |
|
ACCESS_SECRET = '---- Access token secret here ----' |
|
SCREEN_NAME = '---- Screen name here ----' |
|
|
|
api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET) |
|
|
|
pygame.mixer.init() |
|
s0 = pygame.mixer.Sound("scream00.wav") |
|
s1 = pygame.mixer.Sound("scream01.wav") |
|
s2 = pygame.mixer.Sound("scream02.wav") |
|
s3 = pygame.mixer.Sound("scream03.wav") |
|
sounds=[s0, s1, s2, s3] |
|
|
|
# sounds[2] |
|
|
|
GPIO.setmode(GPIO.BCM) |
|
|
|
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) |
|
|
|
lastTweet = "" |
|
i = 0 |
|
|
|
try: |
|
user_timeline = api.get_user_timeline(screen_name=SCREEN_NAME, count=1) |
|
except TwythonError as e: |
|
print e |
|
|
|
for tweets in user_timeline: |
|
lastTweet = tweets['text'].encode('utf-8') |
|
|
|
print 'last tweet: ' + lastTweet |
|
|
|
# PANIC (45 total panics) |
|
endPart = lastTweet[7:] |
|
lastNumberString = endPart[0:len(endPart) - 14] |
|
|
|
print 'last number: ' + lastNumberString |
|
|
|
# int(sys.argv[1]) |
|
i = int(lastNumberString) + 1 |
|
|
|
isDown = False |
|
|
|
print '...ready to panic!' |
|
|
|
while True: |
|
input_state = GPIO.input(18) |
|
if input_state == False and isDown == False: |
|
isDown = True |
|
message = "PANIC (" + str(i) + " total panics)" |
|
print('Button Pressed: ' + message) |
|
try: |
|
api.update_status(status=message) |
|
i = i + 1 |
|
except TwythonError as e: |
|
print e |
|
|
|
soundIndex = random.randrange(0, 4) |
|
sound = sounds[soundIndex] |
|
sound.play() |
|
|
|
|
|
time.sleep(0.2) |
|
elif input_state == True: |
|
isDown = False |