示例#1
0
def main():
	if len(sys.argv) >= 3:
		artist = sys.argv[1]
		database = sys.argv[2]
		#Number of songs to be processed
		if len(sys.argv) >= 4:
			n = sys.argv[3]
		else:
			n = 100
		style = ""
		db = sqlite3.connect(database)
		cursor = db.cursor()
		rv = artist_search(artist, style, n)
		for song in rv["songs"]:
			id = song["id"]
			response = en.get('song/profile', api_key=API_KEY, id=id, bucket="audio_summary")
			sp = response["songs"][0]
			cursor.execute("INSERT INTO songs VALUES(?,?,?,?,?,?,?,?,?,?,?);", 
							(sp["title"], sp["artist_name"], rs.get_bpm(sp), rs.get_time_sig(sp), rs.get_key(sp), sp["id"], sp["audio_summary"]["analysis_url"], 
							rs.get_duration(sp), rs.get_speechiness(sp), rs.get_loudness(sp), "null"))
		db.commit()
		cursor.close()
		db.close()
	else:
		print "Usage: python song_query.py <artist name> <output database file> <number of songs to process>"
		sys.exit(0)
示例#2
0
def main():
	if len(sys.argv) > 3:
		filepath = sys.argv[1]
		database_name = sys.argv[2]
		artist = str(sys.argv[3])
		r = read_songs(filepath,artist)		
		#Create SQL database
		db = sqlite3.connect(database_name)
		cursor = db.cursor()
		print song
		sp = r[song]
		cursor.execute("INSERT INTO songs VALUES(?,?,?,?,?,?,?,?,?,?,?);", (sp["title"],sp["artist_name"], rs.get_bpm(sp), rs.get_time_sig(sp), rs.get_key(sp), sp["id"], sp["analysis_url"], rs.get_duration(sp), rs.get_speechiness(sp), rs.get_loudness(sp), buffer(str(sp)) ))
		db.commit()
		
	else:
		print "Usage: python read_songs_artist.py <text file of songs> <database> <artist name>"