<commit_before>import pygame
# from collections import deque
pygame.display.init()
pygame.joystick.init()
stick = pygame.joystick.Joystick(pygame.joystick.get_count()-1)
stick.init()

numaxes = stick.get_numaxes()
numbuttons = stick.get_numbuttons()
numhats = stick.get_numhats()
# print "numaxes:", numaxes

pygame.event.set_allowed([pygame.JOYBUTTONDOWN, pygame.JOYBUTTONUP, pygame.JOYAXISMOTION])

P1_EVENT_SEQUENCE = []
P2_EVENT_SEQUENCE = []

def read_p1(evt):
	# print evt
	if evt.type == pygame.JOYAXISMOTION:
		value = round(evt.value)
		# print "joy axis motion", evt.type, value
		if evt.axis == 6:
			if value == -1:
				return "left"
			elif value == 1:
				return "right"
		elif evt.axis == 7:
			if value == -1:
				return "up"
			elif value == 1:
				return "down"
	elif evt.type == pygame.JOYBUTTONDOWN:
		if evt.button == 12:
			return "triangle"
		elif evt.button == 13:
			return "o"
		elif evt.button == 14:
			return "x"
		elif evt.button == 15:
			return "square"
		elif evt.button == 20:
			return "select"
		elif evt.button == 21:
			return "start"
	elif evt.type == pygame.JOYBUTTONUP:
		# do we actually need to track the up events?
		pass
	return False # if nothing matched return false

def read_p2(evt):
	# print evt
	if evt.type == pygame.JOYAXISMOTION:
		value = round(evt.value)
		if evt.axis == 3:
			if value == -1:
				return "up"
			elif value == 1:
				return "down"
		elif evt.axis == 2:
			if value == -1:
				return "left"
			elif value == 1:
				return "right"
	elif evt.type == pygame.JOYBUTTONDOWN:
		if evt.button == 0:
			return "triangle"
		elif evt.button == 1:
			return "o"
		elif evt.button == 2:
			return "x"
		elif evt.button == 3:
			return "square"
		elif evt.button == 8:
			return "select"
		elif evt.button == 9:
			return "start"
	elif evt.type == pygame.JOYBUTTONUP:
		# do we actually need to track the up events?
		pass
	return False # if nothing matched return false

def read_event(evt):
	# left side (player 1)
	# up: 		get_axis(8) == -1
	# down:		get_axis(8) == 1
	# left:		get_axis(7) == -1
	# right:	get_axis(7) == 1
	# get_axis(7) and get_axis(8)
	# triangle:		get_button(12)
	# o:			get_button(13)
	# x:			get_button(14)
	# square:		get_button(15)
	# select: 		get_button(20)
	# start:		get_button(21)

	# right side (player 2)
	# up: 		get_axis(4) == -1
	# down:		get_axis(4) == 1
	# left:		get_axis(3) == -1
	# right:	get_axis(3) == 1
	# get_axis(3) and get_axis(4)
	# triangle:		get_button(0)
	# o:			get_button(1)
	# x:			get_button(2)
	# square:		get_button(3)
	# select: 		get_button(8)
	# start:		get_button(9)
	# print pygame.event.event_name(evt.type)
	# print evt

	p1 = read_p1(evt)
	# print evt, p1
	if p1 != False:
		print "p1:", p1
		P1_EVENT_SEQUENCE.append(p1)
		parse_event_sequence(P1_EVENT_SEQUENCE)
		return True
	else:
		p2 = read_p2(evt)
		if p2 != False:
			print "p2:",p2
			P2_EVENT_SEQUENCE.append(p2)
			parse_event_sequence(P2_EVENT_SEQUENCE)
			return True
	return False

import shlex, subprocess
from subprocess import call,check_output


def staging_deploy():
	call(["open","http://inewsdeploy.prvt.nytimes.com/projects/145/stages/331/deployments/new?task=deploy"])
def nice_moves():
	call(["osascript", "-e", '"set Volume 10"'])
	call(["say", "-v", 'agnes', "-r", "270", '"nice moves"'])
def git_commit():
	subprocess.Popen(shlex.split("git commit -am 'Dancing out a commit'"), cwd="/Users/204377/Desktop/dancing_desk/")
	tweet("The dancing desk just committed! https://github.com/albertsun/dancing_desk/commits/master")

def git_push():
	subprocess.Popen(shlex.split("git push origin master"), cwd="/Users/204377/Desktop/dancing_desk/")

import tweepy
from twitter_credentials import *

def tweet(text="The dancing desk is at it again!"):
	auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
	auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
	api = tweepy.API(auth)
	api.update_status

COMMANDS = {
	"staging_deploy": staging_deploy,
	"nice_moves": nice_moves,
	"git_commit": git_commit,
	"git_push": git_push
}
KEYWORDS = ["up","down","left","right","triangle","o","x","square","select","start"]
PATTERNS = [
	[["up", "right", "down", "left"], "squiggle"],
	[["up"], "up"],
	[["square","square","square"], "git_commit"],
	[["o","o","o"], "git_push"],
	[["select","start"], "staging_deploy"],
	[["up","up","down","down","left","right","left","right","o","x","start"], "nice_moves"]
]

def parse_event_sequence(seq):
	# print seq
	for pat,out in PATTERNS:
		if len(seq) >= len(pat) and seq[len(seq)-len(pat):] == pat:
			if COMMANDS.has_key(out): COMMANDS[out]()
			print out + "!"


while True:
	# pygame.event.pump()<commit_msg>Dancing out a commit<commit_after>import pygame
# from collections import deque
pygame.display.init()
pygame.joystick.init()
stick = pygame.joystick.Joystick(pygame.joystick.get_count()-1)
stick.init()

numaxes = stick.get_numaxes()
numbuttons = stick.get_numbuttons()
numhats = stick.get_numhats()
# print "numaxes:", numaxes

pygame.event.set_allowed([pygame.JOYBUTTONDOWN, pygame.JOYBUTTONUP, pygame.JOYAXISMOTION])

P1_EVENT_SEQUENCE = []
P2_EVENT_SEQUENCE = []

def read_p1(evt):
	# print evt
	if evt.type == pygame.JOYAXISMOTION:
		value = round(evt.value)
		# print "joy axis motion", evt.type, value
		if evt.axis == 6:
			if value == -1:
				return "left"
			elif value == 1:
				return "right"
		elif evt.axis == 7:
			if value == -1:
				return "up"
			elif value == 1:
				return "down"
	elif evt.type == pygame.JOYBUTTONDOWN:
		if evt.button == 12:
			return "triangle"
		elif evt.button == 13:
			return "o"
		elif evt.button == 14:
			return "x"
		elif evt.button == 15:
			return "square"
		elif evt.button == 20:
			return "select"
		elif evt.button == 21:
			return "start"
	elif evt.type == pygame.JOYBUTTONUP:
		# do we actually need to track the up events?
		pass
	return False # if nothing matched return false

def read_p2(evt):
	# print evt
	if evt.type == pygame.JOYAXISMOTION:
		value = round(evt.value)
		if evt.axis == 3:
			if value == -1:
				return "up"
			elif value == 1:
				return "down"
		elif evt.axis == 2:
			if value == -1:
				return "left"
			elif value == 1:
				return "right"
	elif evt.type == pygame.JOYBUTTONDOWN:
		if evt.button == 0:
			return "triangle"
		elif evt.button == 1:
			return "o"
		elif evt.button == 2:
			return "x"
		elif evt.button == 3:
			return "square"
		elif evt.button == 8:
			return "select"
		elif evt.button == 9:
			return "start"
	elif evt.type == pygame.JOYBUTTONUP:
		# do we actually need to track the up events?
		pass
	return False # if nothing matched return false

def read_event(evt):
	# left side (player 1)
	# up: 		get_axis(8) == -1
	# down:		get_axis(8) == 1
	# left:		get_axis(7) == -1
	# right:	get_axis(7) == 1
	# get_axis(7) and get_axis(8)
	# triangle:		get_button(12)
	# o:			get_button(13)
	# x:			get_button(14)
	# square:		get_button(15)
	# select: 		get_button(20)
	# start:		get_button(21)

	# right side (player 2)
	# up: 		get_axis(4) == -1
	# down:		get_axis(4) == 1
	# left:		get_axis(3) == -1
	# right:	get_axis(3) == 1
	# get_axis(3) and get_axis(4)
	# triangle:		get_button(0)
	# o:			get_button(1)
	# x:			get_button(2)
	# square:		get_button(3)
	# select: 		get_button(8)
	# start:		get_button(9)
	# print pygame.event.event_name(evt.type)
	# print evt

	p1 = read_p1(evt)
	# print evt, p1
	if p1 != False:
		print "p1:", p1
		P1_EVENT_SEQUENCE.append(p1)
		parse_event_sequence(P1_EVENT_SEQUENCE)
		return True
	else:
		p2 = read_p2(evt)
		if p2 != False:
			print "p2:",p2
			P2_EVENT_SEQUENCE.append(p2)
			parse_event_sequence(P2_EVENT_SEQUENCE)
			return True
	return False

import shlex, subprocess
from subprocess import call,check_output


def staging_deploy():
	call(["open","http://inewsdeploy.prvt.nytimes.com/projects/145/stages/331/deployments/new?task=deploy"])
def nice_moves():
	call(["osascript", "-e", '"set Volume 10"'])
	call(["say", "-v", 'agnes', "-r", "270", '"nice moves"'])

import tweepy
from twitter_credentials import *
twitter_auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
twitter_auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter_client = tweepy.API(twitter_auth)

def tweet(text="The dancing desk is at it again!"):
	print "tweeting:",text
	twitter_client.update_status(text)

def git_commit():
	subprocess.Popen(shlex.split("git commit -am 'Dancing out a commit'"), cwd="/Users/204377/Desktop/dancing_desk/")
	tweet("The dancing desk just committed! https://github.com/albertsun/dancing_desk/commits/master")

def git_push():
	subprocess.Popen(shlex.split("git push origin master"), cwd="/Users/204377/Desktop/dancing_desk/")

COMMANDS = {
	"staging_deploy": staging_deploy,
	"nice_moves": nice_moves,
	"git_commit": git_commit,
	"git_push": git_push,
	"tweet": tweet
}
KEYWORDS = ["up","down","left","right","triangle","o","x","square","select","start"]
PATTERNS = [
	[["up", "right", "down", "left"], "squiggle"],
	[["up"], "up"],
	[["x", "left", "triangle"], "tweet"],
	[["square","square","square"], "git_commit"],
	[["o","o","o"], "git_push"],
	[["select","start"], "staging_deploy"],
	[["up","up","down","down","left","right","left","right","o","x","start"], "nice_moves"]
]

def parse_event_sequence(seq):
	# print seq
	for pat,out in PATTERNS:
		if len(seq) >= len(pat) and seq[len(seq)-len(pat):] == pat:
			if COMMANDS.has_key(out): COMMANDS[out]()
			print out + "!"


while True:
	# pygame.event.pump()
{'fraction_non_alphanumeric': 0.16488063660477453, 'fraction_numerical': 0.02440318302387268, 'mean_word_length': 4.153635866593767, 'pattern_counts': {'":': 9, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6047100', 'n_tokens_mistral': 4123, 'n_tokens_neox': 3794, 'n_words': 852}