Skip to content

Instantly share code, notes, and snippets.

@oldaccountarchived
Created October 29, 2014 21:03
Show Gist options
  • Save oldaccountarchived/5c07f26558fb95edcec7 to your computer and use it in GitHub Desktop.
Save oldaccountarchived/5c07f26558fb95edcec7 to your computer and use it in GitHub Desktop.
with open('tracks_per_year.txt','r') as in_file:
with open('musicinput.sql','w') as out_file:
for x in in_file:
SQL_in = x.rstrip() #Get rid of those newlines
SQL_out = 'INSERT INTO Music VALUES('
SQL_vals = SQL_in.split('<SEP>')
# Grab vals from split
year = SQL_vals[0]
song_ID = SQL_vals[1]
artist = SQL_vals[2]
song = SQL_vals[3]
# Passes artist name to function to generate key.
# artist_ID = toKey(artist)
# Once that function is written iser "artist_ID + ',' +" below
SQL_out += ('\'' + artist + '\'' + ',' + '\'' + song_ID + ',' + song + ',' +
year + ');')
print >> out_file, SQL_out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment