forked from bmcfee/hypergraph_playlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildYearmap.py
executable file
·49 lines (35 loc) · 1.06 KB
/
buildYearmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
'''
CREATED:2012-03-21 17:44:29 by Brian McFee <bmcfee@cs.ucsd.edu>
Construct a song=>year/era mapping
Usage:
./buildYearmap.py output.pickle playlist.pickle /path/to/track_metadata.db
'''
import sys
import sqlite3
import numpy
import cPickle as pickle
def loadSongs(infile):
with open(infile, 'r') as f:
songs = pickle.load(f)['songs']
pass
return songs
def getYearMap(songs, dbc):
X = {}
cur = dbc.cursor()
cur.execute('''SELECT song_id, year FROM songs WHERE year > 0''')
for (song_id, year) in cur:
if song_id not in songs:
continue
X[song_id] = {'YEAR_%4d' % year, 'DECADE_%4d' % int(10 * numpy.floor(float(year) / 10)), 'DECADE_%4d' % int(10 * numpy.floor((float(year) + 5)/10) - 5)}
pass
return X
if __name__ == '__main__':
songs = loadSongs(sys.argv[2])
with sqlite3.connect(sys.argv[3]) as dbc:
yearmap = getYearMap(songs, dbc)
pass
with open(sys.argv[1], 'w') as f:
pickle.dump({'X': yearmap}, f)
pass
pass