Esempio n. 1
0
 def get(self):
     self.write(
         self.render_string("bare_header.html", title="Adding Groups"))
     self.write("<h2>Associating Groups</h2>")
     self.write("<h3>These Songs:</h3><ul>")
     songs = cache.get_user(self.user, "admin_associate_groups_songs") or []
     for song_id in songs:
         song = Song.load_from_id(song_id)
         self.write("<li>%s</li>" % song.data['title'])
     self.write("</ul><h3>Songs In These Albums:</h3><ul>")
     albums = cache.get_user(self.user,
                             "admin_associate_groups_albums") or []
     for album_set in albums:
         album = Album.load_from_id(album_set[0])
         self.write(
             "<li>%s (%s)</li>" %
             (album.data['name'], config.station_id_friendly[album_set[1]]))
     self.write("</ul><select id='associate_group_id'>")
     for row in db.c.fetch_all(
             "SELECT group_id, group_name FROM r4_groups ORDER BY group_name"
     ):
         self.write("<option value='%s'>%s</option>" %
                    (row['group_id'], row['group_name']))
     self.write("</select><br />")
     self.write(
         "<button onclick=\"window.location.href='/admin/tools/associate_groups_finish/' + document.getElementById('associate_group_id').value\">Associate</button>"
     )
     self.write(
         "<br /><br /><a href='/admin/tools/associate_groups_cache_reset'>Reset the list above.</a>"
     )
     self.write(self.render_string("basic_footer.html"))
Esempio n. 2
0
	def get(self, group_id):	#pylint: disable=W0221
		group = SongGroup.load_from_id(group_id)
		songs = cache.get_user(self.user, "admin_associate_groups_songs") or []
		cache.set_user(self.user, "admin_associate_groups_songs", [])
		for song_id in songs:
			group.associate_song_id(song_id)
		albums = cache.get_user(self.user, "admin_associate_groups_albums") or []
		cache.set_user(self.user, "admin_associate_groups_albums", [])
		for album_set in albums:
			album = Album.load_from_id_with_songs(album_set[0], album_set[1])
			for song in album.data['songs']:
				group.associate_song_id(song['id'])
		self.write(self.render_string("bare_header.html", title="Added Groups"))
		self.write("<p>Now associated.</p><p><a href='/admin/tools/associate_groups'>Start over.</a></p>")
		self.write(self.render_string("basic_footer.html"))
Esempio n. 3
0
	def get(self, group_id):
		group = SongGroup.load_from_id(group_id)
		songs = cache.get_user(self.user, "admin_associate_groups_songs") or []
		cache.set_user(self.user, "admin_associate_groups_songs", [])
		for song_id in songs:
			group.associate_song_id(song_id)
		albums = cache.get_user(self.user, "admin_associate_groups_albums") or []
		cache.set_user(self.user, "admin_associate_groups_albums", [])
		for album_set in albums:
			album = Album.load_from_id_with_songs(album_set[0], album_set[1])
			for song in album.data['songs']:
				group.associate_song_id(song['id'])
		self.write(self.render_string("bare_header.html", title="Added Groups"))
		self.write("<p>Now associated.</p><p><a href='/admin/tools/associate_groups'>Start over.</a></p>")
		self.write(self.render_string("basic_footer.html"))
Esempio n. 4
0
	def get(self):
		self.write(self.render_string("bare_header.html", title="Adding Groups"))
		self.write("<h2>Associating Groups</h2>")
		self.write("<h3>These Songs:</h3><ul>")
		songs = cache.get_user(self.user, "admin_associate_groups_songs") or []
		for song_id in songs:
			song = Song.load_from_id(song_id)
			self.write("<li>%s</li>" % song.data['title'])
		self.write("</ul><h3>Songs In These Albums:</h3><ul>")
		albums = cache.get_user(self.user, "admin_associate_groups_albums") or []
		for album_set in albums:
			album = Album.load_from_id(album_set[0])
			self.write("<li>%s (%s)</li>" % (album.data['name'], config.station_id_friendly[album_set[1]]))
		self.write("</ul><select id='associate_group_id'>")
		for row in db.c.fetch_all("SELECT group_id, group_name FROM r4_groups ORDER BY group_name"):
			self.write("<option value='%s'>%s</option>" % (row['group_id'], row['group_name']))
		self.write("</select><br />")
		self.write("<button onclick=\"window.location.href='/admin/tools/associate_groups_finish/' + document.getElementById('associate_group_id').value\">Associate</button>")
		self.write("<br /><br /><a href='/admin/tools/associate_groups_cache_reset'>Reset the list above.</a>")
		self.write(self.render_string("basic_footer.html"))
Esempio n. 5
0
	print "Adding r4_album_faves table."

	db.c.update(" \
		CREATE TABLE r4_album_faves ( \
			album_id				INTEGER		NOT NULL, \
			user_id					INTEGER		NOT NULL, \
			album_fave				BOOLEAN \
		)")
	db.c.create_idx("r4_album_faves", "user_id", "album_id") 	#Should be handled by primary key.
	db.c.create_idx("r4_album_faves", "album_fave")
	db.c.create_delete_fk("r4_album_faves", "r4_albums", "album_id", create_idx=False)
	db.c.create_delete_fk("r4_album_faves", "phpbb_users", "user_id", create_idx=False)

	print "Populating album_faves table..."

	for row in db.c.fetch_all("SELECT album_id, user_id FROM r4_album_ratings WHERE album_fave = TRUE"):
		if not db.c.fetch_var("SELECT COUNT(*) FROM r4_album_faves WHERE album_id = %s AND user_id = %s", (row['album_id'], row['user_id'])):
			db.c.update("INSERT INTO r4_album_faves (album_id, user_id, album_fave) VALUES (%s, %s, TRUE)", (row['album_id'], row['user_id']))

	print "Removing old column..."

	db.c.update("ALTER TABLE r4_album_ratings DROP COLUMN album_fave")

	print "Recalculating ratings for testing..."
	for row in db.c.fetch_all("SELECT DISTINCT album_id, sid FROM r4_album_sid"):
		alb = Album.load_from_id_sid(row['album_id'], row['sid'])
		alb.update_all_user_ratings()
		alb.update_fave_count()

	print "Done"
Esempio n. 6
0
import argparse

from libs import config
from libs import db
from rainwave.playlist import Album

if __name__ == "__main__":
	parser = argparse.ArgumentParser(description="Rainwave API server.")
	parser.add_argument("--config", default=None)
	args = parser.parse_args()
	config.load(args.config)
	db.connect()

	albums = db.c.fetch_list("SELECT album_id FROM r4_albums")
	i = 0
	for album_id in albums:
		txt = "Album %s / %s" % (i, len(albums))
		txt += " " * (80 - len(txt))
		print "\r" + txt,
		i += 1
		
		a = Album.load_from_id(album_id)
		a.reconcile_sids()
		a.update_all_user_ratings()
		a.update_rating()
Esempio n. 7
0
#!/usr/bin/env python

import argparse

from libs import config
from libs import db
from rainwave.playlist import Album

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Recalculates all album ratings, both global ratings and for every user.  Takes a while."
    )
    parser.add_argument("--config", default=None)
    args = parser.parse_args()
    config.load(args.config)
    db.connect()

    albums = db.c.fetch_list("SELECT album_id FROM r4_albums")
    i = 0
    for album_id in albums:
        txt = "Album %s / %s" % (i, len(albums))
        txt += " " * (80 - len(txt))
        print("\r" + txt, end="")
        i += 1

        a = Album.load_from_id(album_id)
        a.reconcile_sids()
        a.update_all_user_ratings()
        a.update_rating()
Esempio n. 8
0
                          create_idx=False)
    db.c.create_delete_fk("r4_album_faves",
                          "phpbb_users",
                          "user_id",
                          create_idx=False)

    print "Populating album_faves table..."

    for row in db.c.fetch_all(
            "SELECT album_id, user_id FROM r4_album_ratings WHERE album_fave = TRUE"
    ):
        if not db.c.fetch_var(
                "SELECT COUNT(*) FROM r4_album_faves WHERE album_id = %s AND user_id = %s",
            (row['album_id'], row['user_id'])):
            db.c.update(
                "INSERT INTO r4_album_faves (album_id, user_id, album_fave) VALUES (%s, %s, TRUE)",
                (row['album_id'], row['user_id']))

    print "Removing old column..."

    db.c.update("ALTER TABLE r4_album_ratings DROP COLUMN album_fave")

    print "Recalculating ratings for testing..."
    for row in db.c.fetch_all(
            "SELECT DISTINCT album_id, sid FROM r4_album_sid"):
        alb = Album.load_from_id_sid(row['album_id'], row['sid'])
        alb.update_all_user_ratings()
        alb.update_fave_count()

    print "Done"