def generation_null_relation(cls, sound_quantity): DBSession.query(cls).delete() for i in xrange(1, sound_quantity + 1): for j in xrange(1, sound_quantity + 1): DBSession.add( Relation(left_sound_id=i, weight=int(100 - 100 / 1.618), right_sound_id=j))
def generation_new_relation(cls, sound_quantity): DBSession.query(cls).delete() for i in xrange(1, sound_quantity + 1): for j in xrange(1, sound_quantity + 1): DBSession.add( Relation(left_sound_id=i, weight=random.randint(0, 100), right_sound_id=j))
def upload_files(cls, directory): tree = 'C:\\Users\\Leafmen\\Desktop\\python\\diploma\\webplayer\\webplayer\\public' directory = tree + '\\music' + directory #files = listdir(tg.url('/music' + directory)) files = listdir(directory) for file in files: sound = {} meta = mutagen.File(directory + '/' + file) try: sound['name'] = str(meta['TIT2']).encode('utf8') except: sound['name'] = 'Null' try: sound['date'] = str(meta['TDRC']).encode('utf8') except: sound['date'] = 'Null' try: sound['album'] = str(meta['TALB']).encode('utf8') except: sound['album'] = 'Null' try: sound['genre'] = str(meta['TCON']).encode('utf8') except: sound['genre'] = 'Null' try: sound['artist'] = str(meta['TPE1']).encode('utf8') except: sound['artist'] = 'Null' sound['data'] = str(file).encode('utf8') try: pic = meta.tags.getall("APIC")[0].data with open(tree + '\\img\\%s.jpg' % sound['data'], 'wb') as img: img.write(pic) sound['picture'] = '%s.jpg' % sound['data'] except: sound['picture'] = 'Null' DBSession.add( Sound(sound_name=sound['name'], date=sound['date'], album=sound['album'], genre=sound['genre'], artist=sound['artist'], data=sound['data'], picture=sound['picture'], user_id=1))
def generation_test_data(cls, quantity): try: last_sound = DBSession.query(cls).order_by( cls.sound_id.desc()).first() last = last_sound.sound_id + 1 except: last = 1 for i in xrange(last, last + quantity): DBSession.add( Sound(sound_name='Test Song #%s' % i, data='Test Data #%s' % i, user_id=1))