<commit_before>#!/usr/bin/env python
#import numpy
import read_audio
import getopt
import sys
import match
import datastore

"""
This is the main executable file we'll run for assn4.

Just testing fft for now or whatever
"""

"""
parse:
parse the files passed to us at the command line

INPUT: Command line arguments without the leading reference
OUTPUT: Duple of the file paths
"""
def parse_args(argv):

	#delcare audio file 1 (eventually artist audio?)
	true_audio = ""
	#delcare audio file 2 (eventually candidate audio?)
	suspect_audio = ""

	#temporary flag for checking which file is which
	true_audio_registered = False

	#get the audio arguments and options
	try:
	  option_value_hash, command_line_args = getopt.getopt(argv,"f:d:")
	  #not using command_line_args, arguments in options_value_hash (-option => argument)

	  #check number of options
	  if(len(option_value_hash) < 2):
	  	print 'ERROR: incorrect command line'
	  	sys.exit(2)

	except getopt.GetoptError:
	  print 'ERROR: incorrect command line'
	  sys.exit(2)

	#should we be given valid arguments, lets take a look
	for option, arg in option_value_hash:
		#if its a file we were passed
		if option in ("-f", "-d"):
			#check the order it was passed in
			if not true_audio_registered:
				true_audio = (option, arg)
				true_audio_registered = True
			#otherwise
			else:
				suspect_audio = (option, arg)
				break


	return true_audio, suspect_audio


"""
main:
lets grab those input files shall we?

INPUT: Command line arguments without the leading reference
OUTPUT: Results of dan's main functionality a.k.a. commparing two audio files
"""
def main(argv):

	#delcare audio file 1 (eventually artist audio?)
	true_audio = ""
	#delcare audio file 2 (eventually candidate audio?)
	suspect_audio = ""

	#parse the audio files from the arguments
	true_audio, suspect_audio = parse_args(argv)

	#validate that these audio files are legit
	if (not (read_audio.validate_input(true_audio) and read_audio.validate_input(suspect_audio))):
		sys.exit(2)

	true_audio = read_audio.create_file_array(true_audio)
	suspect_audio = read_audio.create_file_array(suspect_audio)

	#delete current tmp files if they exist
	read_audio.delete_temp_file('/tmp/fingerprints.txt')
	read_audio.delete_temp_file('/tmp/songs.txt')

	for audio_path in true_audio:
		datastore.add_fingerprints(audio_path)

	matches = []
	for audio_path in suspect_audio:
		match_data = match.match_song_to_db(audio_path)
		if match_data:
			matches.append((audio_path, match_data))

	print matches

#run maine (1: lops off the leading reference)
main(sys.argv[1:])<commit_msg>shortened lines in dan.py<commit_after>#!/usr/bin/env python
#import numpy
import read_audio
import getopt
import sys
import match
import datastore

"""
This is the main executable file we'll run for assn4.

Just testing fft for now or whatever
"""

"""
parse:
parse the files passed to us at the command line

INPUT: Command line arguments without the leading reference
OUTPUT: Duple of the file paths
"""
def parse_args(argv):

	#delcare audio file 1 (eventually artist audio?)
	true_audio = ""
	#delcare audio file 2 (eventually candidate audio?)
	suspect_audio = ""

	#temporary flag for checking which file is which
	true_audio_registered = False

	#get the audio arguments and options
	try:
	  option_value_hash, command_line_args = getopt.getopt(argv,"f:d:")
	  # not using command_line_args, arguments in 
	  # options_value_hash (-option => argument)

	  #check number of options
	  if(len(option_value_hash) < 2):
	  	print 'ERROR: incorrect command line'
	  	sys.exit(2)

	except getopt.GetoptError:
	  print 'ERROR: incorrect command line'
	  sys.exit(2)

	#should we be given valid arguments, lets take a look
	for option, arg in option_value_hash:
		#if its a file we were passed
		if option in ("-f", "-d"):
			#check the order it was passed in
			if not true_audio_registered:
				true_audio = (option, arg)
				true_audio_registered = True
			#otherwise
			else:
				suspect_audio = (option, arg)
				break


	return true_audio, suspect_audio


"""
main:
lets grab those input files shall we?

INPUT: Command line arguments without the 
	   leading reference
OUTPUT: Results of dan's main functionality 
		a.k.a. commparing two audio files
"""
def main(argv):

	#delcare audio file 1 (eventually artist audio?)
	true_audio = ""
	#delcare audio file 2 (eventually candidate audio?)
	suspect_audio = ""

	#parse the audio files from the arguments
	true_audio, suspect_audio = parse_args(argv)

	#validate that these audio files are legit
	if (not (read_audio.validate_input(true_audio) 
		and read_audio.validate_input(suspect_audio))):
		sys.exit(2)

	true_audio = read_audio.create_file_array(true_audio)
	suspect_audio = read_audio.create_file_array(suspect_audio)

	#delete current tmp files if they exist
	read_audio.delete_temp_file('/tmp/fingerprints.txt')
	read_audio.delete_temp_file('/tmp/songs.txt')

	for audio_path in true_audio:
		datastore.add_fingerprints(audio_path)

	matches = []
	for audio_path in suspect_audio:
		match_data = match.match_song_to_db(audio_path)
		if match_data:
			matches.append((audio_path, match_data))

	print matches

#run maine (1: lops off the leading reference)
main(sys.argv[1:])
{'fraction_non_alphanumeric': 0.08377760853008377, 'fraction_numerical': 0.004188880426504189, 'mean_word_length': 4.576433121019108, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '4285329', 'n_tokens_mistral': 1802, 'n_tokens_neox': 1641, 'n_words': 564}