Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A couple improvements Aliases and Text to Speech #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions retaliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import json
import urllib2
import base64
import os

import usb.core
import usb.util
Expand All @@ -93,6 +94,14 @@
# is milli-seconds. The number after "fire" denotes the number of rockets
# to shoot.
#
ALIAS = {
"will.external" : "will",
"will" : "will",
"tom_personal" : "tom",
"tom" : "tom",
"chris" : "chris"
}

COMMAND_SETS = {
"will" : (
("zero", 0), # Zero/Park to know point (bottom-left)
Expand Down Expand Up @@ -264,16 +273,11 @@ def run_command_set(commands):


def jenkins_target_user(user):
match = False
# Not efficient but our user list is probably less than 1k.
# Do a case insenstive search for convenience.
for key in COMMAND_SETS:
if key.lower() == user.lower():
if ALIAS.get(user.lower()) != None:
# We have a command set that targets our user so got for it!
run_command_set(COMMAND_SETS[key])
match = True
break
if not match:
run_command_set(COMMAND_SETS[ALIAS.get(user.lower())])
else:
print "WARNING: No target command set defined for user %s" % user


Expand Down Expand Up @@ -311,6 +315,14 @@ def jenkins_wait_for_event():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', JENKINS_NOTIFICATION_UDP_PORT))

#In Ubuntu/Mint you need to install mplayer and chmod u+x speech.sh
speech = os.path.dirname(os.path.realpath(__file__)) + "/speech.sh "
volume = '10 ' # up to 50
voice = 'en ' #Google's API is not documented however some local codes (i.e. en_GB) seem to work just fine.
message = " you broke the build it's time for retaliation"
#change to True if you want to hear the voice!
skynet_voice = False

while True:
data, addr = sock.recvfrom(8 * 1024)
try:
Expand All @@ -321,9 +333,12 @@ def jenkins_wait_for_event():
target = jenkins_get_responsible_user(notification_data["name"])
if target == None:
print "WARNING: Could not identify the user who broke the build!"
continue

continue
print "Build Failed! Targeting user: " + target
#printing is nice but an Skynet voice is more menacing!
if skynet_voice:
#TODO: change this to Popen to do it async.
os.system(speech + volume + voice + target + message)
jenkins_target_user(target)
except:
pass
Expand Down Expand Up @@ -356,4 +371,4 @@ def main(args):


if __name__ == '__main__':
main(sys.argv)
main(sys.argv)
7 changes: 7 additions & 0 deletions speech.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
#Taken from http://elinux.org/RPi_Text_to_Speech_(Speech_Synthesis)
say() {
SP=${@:3};
echo $SP
local IFS=+;/usr/bin/mplayer -af volume=$1 -ao alsa -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?tl=$2&q=$SP"; }
say $*