Created
September 30, 2010 20:07
-
-
Save JayCuthrell/605235 to your computer and use it in GitHub Desktop.
Revisions
-
qthrul revised this gist
Sep 30, 2010 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -117,4 +117,4 @@ def speak_commits(): if __name__ == '__main__': speak_commits() -
qthrul created this gist
Sep 30, 2010 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,120 @@ # 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()