#print pratham['music'] prat = users.getUser(facebook_id=pratham['facebook_id']) #print prat['music'] #for user in users.getUser(): #pprint(users.getUser(facebook_id=shivam['facebook_id'])) #print user """ # get favourite artist : or/music/tracks/genres/albums artists = list() users = rooms.getRoom(host=apt34["host"])["usersInRoom"] for user in users: for item in user["music"]: if item["category"] == "Musician/band": artists.append(item) l = lastfm() # print "Liked Artists : ",len(artists) likedArtist = len(artists) ratio = 0.6 artistCount = int((120 / likedArtist) * ratio) trackCount = int((120 / likedArtist) * (1 - ratio)) total = likedArtist * artistCount * trackCount print "(likedArtist,artistCount,trackCount)(%s, %s, %s)" % (likedArtist, artistCount, trackCount) print "total : ", total weight_currentness = 0.5 weight_similarness = 0.8 reco = l.getRecommendation(artists, artistCount, trackCount, weight_currentness, weight_similarness) # pprint(reco) l.displayList(reco) # pprint(artists) # if(len(user['music'])==0):continue
def run(self, bind_address, port): print "Starting LastFMProxy " + self.version + "..." s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Set socket options to allow binding to the same address # when the proxy has been closed and then restarted: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((bind_address, port)) s.listen(5) print "Connecting to last.fm server..." self.lastfm = lastfm.lastfm(); self.lastfm.connect(self.username, self.hexify(md5.md5(self.password).digest())) #print self.lastfm.info if not self.lastfm.info.has_key("session"): print "Handshake failed." print "DEBUG:", self.lastfm.info s.close() return if self.lastfm.info["session"] == "FAILED": print "Handshake failed. Bad login info, perhaps?" print "DEBUG:", self.lastfm.info s.close() return self.audioscrobbler = audioscrobbler.audioscrobbler() self.audioscrobbler.handshake(self.username, self.password, self.version) self.bookmarks = [] try: f = open(os.path.join(self.basedir, "bookmarks.txt"), "r") for line in f.readlines(): self.bookmarks.append(string.rstrip(line)) f.close() except IOError: try: f = open(os.path.join(self.basedir, "stations.txt"), "r") for line in f.readlines(): self.bookmarks.append(string.rstrip(line)) f.close() except IOError: pass # Minor prettification if bind_address == "127.0.0.1" or bind_address == "0.0.0.0": bind_address = "localhost" print "To tune in, point your browser to:" print " http://" + bind_address + ":" + str(port) + "/" runningthreads = [] try: while not self.quit: (clientsocket, address) = s.accept() if self.lastfm.debug: sys.stderr.write("\nGot connection from " + repr(address) + "\n") t = threading.Thread(target=self.gotconnection,args=(clientsocket,)) t.start() runningthreads.append(t) except KeyboardInterrupt: self.quit = 1 print "Shutting down..." for t in runningthreads: t.join() print "Done! Bye!" s.close() return
def topArtists(option): artistsWindow = tkinter.Toplevel() artistsWindow.title("Artists Search Results") width, height = artistsWindow.winfo_screenwidth( ), artistsWindow.winfo_screenheight() artistsWindow.geometry('%dx%d+0+0' % (width, height)) num = combo.current() + 1 header2 = "" if (option == "L"): results = lastfm.lastfm(num, 'artists') header = "Last.fm" elif (option == "B"): results = billb.billb(num, 'artists') header = "Billboard" elif (option == "LB"): results = lastfm.lastfm(num, 'artists') header = "Last.fm" results2 = billb.billb(num, 'artists') header2 = "Billboard" label = tkinter.Label(artistsWindow, text=header, font=("Arial Bold Italics", 40), fg="blue").place(x=0, y=0) artistsList = [None] * (num + 1) for i in range(num + 1): artistsList[i] = "" counter = 0 check = False for row in repr(results): if (row != "\\" and row != "n" and row != "\""): artistsList[counter] += row elif (row == "\\"): check = True elif (row == "n" and check == True): counter += 1 check = False elif (row == "n" and check == False): artistsList[counter] += row dic = {} i = 0 artistsList[0] = artistsList[0][1:] for i in range(num): dic[i] = tkinter.Button( artistsWindow, text=artistsList[i], font=("Arial Bold Italics", 15), bg="blue", fg="white", command=partial(Links, artistsList[i], "artists")).place(x=0, y=(height / 15) * (i / 1.6 + 1)) if (option == "LB"): label2 = tkinter.Label(artistsWindow, text=header2, font=("Arial Bold Italics", 40), fg="blue").place(x=width / 1.8, y=0) artistsList2 = [None] * (num + 1) for i in range(num + 1): artistsList2[i] = "" counter = 0 check = False for row in repr(results2): if (row != "\\" and row != "n" and row != "\""): artistsList2[counter] += row elif (row == "\\"): check = True elif (row == "n" and check == True): counter += 1 check = False elif (row == "n" and check == False): artistsList2[counter] += row dic = {} i = 0 artistsList2[0] = artistsList2[0][1:] for i in range(num): dic[i] = tkinter.Button( artistsWindow, text=artistsList2[i], font=("Arial Bold Italics", 15), bg="blue", fg="white", command=partial(Links, artistsList2[i], "artists")).place( x=width / 1.8, y=(height / 15) * (i / 1.6 + 1)) backButton = tkinter.Button(artistsWindow, text="Go Back", font=("Arial Bold Italics", 40), bg="blue", fg="white", command=artistsWindow.destroy).place( x=width / 2.4, y=height / 1.2)
#print pratham['music'] prat = users.getUser(facebook_id=pratham['facebook_id']) #print prat['music'] #for user in users.getUser(): #pprint(users.getUser(facebook_id=shivam['facebook_id'])) #print user ''' #get favourite artist : or/music/tracks/genres/albums artists = list() users = rooms.getRoom(host=apt34['host'])['usersInRoom'] for user in users: for item in user['music']: if (item['category'] == "Musician/band"): artists.append(item) l = lastfm() #print "Liked Artists : ",len(artists) likedArtist = len(artists) ratio = .6 artistCount = int((120 / likedArtist) * ratio) trackCount = int((120 / likedArtist) * (1 - ratio)) total = likedArtist * artistCount * trackCount print "(likedArtist,artistCount,trackCount)(%s, %s, %s)" % ( likedArtist, artistCount, trackCount) print "total : ", total weight_currentness = .5 weight_similarness = .8 reco = l.getRecommendation(artists, artistCount, trackCount, weight_currentness, weight_similarness) #pprint(reco) l.displayList(reco)
def topSongs(option): songsWindow = tkinter.Toplevel() songsWindow.title("Songs Search Results") width, height = songsWindow.winfo_screenwidth( ), songsWindow.winfo_screenheight() songsWindow.geometry('%dx%d+0+0' % (width, height)) num = combo.current() + 1 header2 = "" if (daily_weekly == 'daily'): if option == "S": results = spotify.spotify(num, 'daily') header = "Spotify" elif option == "L": results = lastfm.lastfm(num, 'songs') header = "Last.fm" elif option == "SL": results = spotify.spotify(num, 'daily') header = "Spotify" results2 = lastfm.lastfm(num, 'songs') header2 = "Last.fm" elif (daily_weekly == 'weekly'): if option == "S": results = spotify.spotify(num, 'weekly') header = "Spotify" elif option == "B": results = billb.billb(num, 'songs') header = "Billboard" elif option == "SB": results = spotify.spotify(num, 'weekly') header = "Spotify" results2 = billb.billb(num, "songs") header2 = "Billboard" label = tkinter.Label(songsWindow, text=header, font=("Arial Bold Italics", 40), fg="blue").place(x=0, y=0) songsList = [None] * (num + 1) for i in range(num + 1): songsList[i] = "" counter = 0 check = False for row in repr(results): if (row != "\\" and row != "n" and row != "\""): songsList[counter] += row elif (row == "\\"): check = True elif (row == "n" and check == True): counter += 1 check = False elif (row == "n" and check == False): songsList[counter] += row dic = {} i = 0 for i in range(num): dic[i] = tkinter.Button( songsWindow, text=songsList[i], font=("Arial Bold Italics", 15), bg="blue", fg="white", command=partial(Links, songsList[i], "songs")).place(x=0, y=(height / 15) * (i / 1.6 + 1)) if (option == "SL" or option == "SB"): label2 = tkinter.Label(songsWindow, text=header2, font=("Arial Bold Italics", 40), fg="blue").place(x=width / 1.8, y=0) songsList2 = [None] * (num + 1) for i in range(num + 1): songsList2[i] = "" counter = 0 check = False for row in repr(results2): if (row != "\\" and row != "n" and row != "\""): songsList2[counter] += row elif (row == "\\"): check = True elif (row == "n" and check == True): counter += 1 check = False elif (row == "n" and check == False): songsList2[counter] += row dic = {} i = 0 for i in range(num): dic[i] = tkinter.Button(songsWindow, text=songsList2[i], font=("Arial Bold Italics", 15), bg="blue", fg="white", command=partial( Links, songsList2[i], "songs")).place( x=width / 1.8, y=(height / 15) * (i / 1.6 + 1)) backButton = tkinter.Button(songsWindow, text="Go Back", font=("Arial Bold Italics", 40), bg="blue", fg="white", command=songsWindow.destroy).place( x=width / 2.4, y=height / 1.2)