set-artist-streamable.py 811 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. import psycopg2 as ordbms
  3. import urllib, urllib2
  4. import xml.etree.cElementTree as ElementTree
  5. class SetArtistStreamable:
  6. def __init__(self):
  7. self.conn = ordbms.connect ("dbname='librefm'")
  8. self.cursor = self.conn.cursor()
  9. def updateAll(self):
  10. """Sets artists streamable property if they have streamable tracks already in the database"""
  11. self.cursor.execute("SELECT DISTINCT(artist.name) FROM artist INNER JOIN track on artist.name=artist_name WHERE track.streamable = 1")
  12. for artist in self.cursor.fetchall():
  13. name = artist[0]
  14. print "marking %s as streamable... " % name
  15. self.cursor.execute("UPDATE artist SET streamable = 1 WHERE name = %s", (name,))
  16. self.conn.commit()
  17. if __name__ == '__main__':
  18. sas = SetArtistStreamable()
  19. sas.updateAll()