-
-
Save gleitz/605345 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CommitBot | |
# An interface for audibly broadcasting commit messages | |
# Tested on OSX | |
# Created by the friendly team at Hunch.com (sharing is caring!) | |
# | |
# Installation | |
# 1. replace USERNAME, PASSWORD, and HOSTNAME below | |
# 2. ... | |
# 3. profit! | |
import time | |
import re | |
import os | |
import random | |
_rev_rx = re.compile('r(\d+)\s\|\s(\w+)\s\|\s.*\s\|(.*)\s\s(.*)') | |
MALE = { | |
'alex': 'Alex', | |
'bruce': 'Bruce', | |
'fred': 'Fred', | |
'junior': 'Junior', | |
'ralph': 'Ralph', | |
} | |
FEMALE = { | |
'agnes': 'Agnes', | |
'kathy': 'Kathy', | |
'princess': 'Princess', | |
'vicki': 'Vicki', | |
'victoria': 'Victoria', | |
} | |
NOVELTY = { | |
'albert': 'Albert', | |
'badnews': 'Bad News', | |
'bahh': 'Bahh', | |
'bells': 'Bells', | |
'boing': 'Boing', | |
'bubbles': 'Bubbles', | |
'cellos': 'Cellos', | |
'deranged': 'Deranged', | |
'goodnews': 'Good News', | |
'hysterical': 'Hysterical', | |
'pipeorgan': 'Pipe Organ', | |
'trinoids': 'Trinoids', | |
'whisper': 'Whisper', | |
'zarvox': 'Zarvox', | |
} | |
VOICES = {}; VOICES.update(MALE); VOICES.update(FEMALE); VOICES.update(NOVELTY); | |
def get_voice(text): | |
options = [x[1:] for x in text.split() if x.startswith('#')] | |
if options: | |
option = options[-1].lower() | |
if option in VOICES: | |
return VOICES[option] | |
elif option == 'male': | |
return random.choice(MALE.values()) | |
elif option == 'female': | |
return random.choice(FEMALE.values()) | |
elif option == 'novelty': | |
return random.choice(NOVELTY.values()) | |
elif option == 'random': | |
return random.choice(VOICES.values()) | |
return '' | |
def remove_hashes(text): | |
return re.sub('((^| )#[^ ]+)', '', text) | |
def clean(x): | |
return remove_hashes(x.replace('"', "'").replace('\n', ' ')) | |
def speak_commits(): | |
revision = 0 | |
try: | |
commit_obj = open("/tmp/commit", "r") | |
local_rev = commit_obj.read().strip() | |
if local_rev: revision = int(local_rev) | |
commit_obj.close() | |
except: | |
pass | |
while(True): | |
try: | |
result = os.popen("svn log --username USERNAME --password PASSWORD HOSTNAME --limit 1").read() | |
cur_rev, username, lines, msg = _rev_rx.findall(result)[0] | |
# Insert nicknames | |
if username == 'volkan': username = 'Steve' # muh-hahaha! | |
if username == 'pcoles': username = 'cobra kai' # muh-hahahahahahaha! | |
if username == 'tp': username = 'barbeque' # muh-hahaha! | |
if username == 'hcooper': username = 'h prod' # hm. | |
if int(cur_rev) > int(revision) and '#silent' not in msg: | |
voice = get_voice(msg) | |
if voice: voice = '-v "%s" ' % voice | |
else: voice = '-v "Vicki" ' | |
string = 'say %s"%s, %s"' % (voice, username, clean(msg)[:250]) # prevent extremely long messages! | |
mute_spotify = """osascript<<END | |
tell application "Spotify" to activate | |
tell application "System Events" | |
tell process "Spotify" | |
click menu item 1 of menu 1 of menu bar item 6 of menu bar 1 | |
end tell | |
end tell""" | |
os.system(mute_spotify) | |
os.system("osascript -e 'tell application \"iTunes\" to set mute to true'") | |
os.popen(string) | |
os.system("osascript -e 'tell application \"iTunes\" to set mute to false'") | |
os.system(mute_spotify) | |
revision = cur_rev | |
commit_obj = open("/tmp/commit", "w") | |
commit_obj.write(revision) | |
commit_obj.close() | |
time.sleep(10) | |
except: | |
time.sleep(10) | |
if __name__ == '__main__': | |
speak_commits() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment