set-artist-streamable.py 811 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/env python
import psycopg2 as ordbms
import urllib, urllib2
import xml.etree.cElementTree as ElementTree


class SetArtistStreamable:


	def __init__(self):
		self.conn = ordbms.connect ("dbname='librefm'")
                self.cursor = self.conn.cursor()


	def updateAll(self):
		"""Sets artists streamable property if they have streamable tracks already in the database"""
		self.cursor.execute("SELECT DISTINCT(artist.name) FROM artist INNER JOIN track on artist.name=artist_name WHERE track.streamable = 1")
		for artist in self.cursor.fetchall():
			name = artist[0]
			print "marking %s as streamable... " % name
			self.cursor.execute("UPDATE artist SET streamable = 1 WHERE name = %s", (name,))
22
			self.conn.commit()
23 24 25 26

if __name__ == '__main__':
	sas = SetArtistStreamable()
	sas.updateAll()