lastfm: remove tasteometer

They removed this feature from the API. What exactly is the point of
Last.fm now, just advertising?
master
mutantmonkey 2016-03-06 14:35:19 -08:00
parent 64d7088adb
commit 984dba9b4b
2 changed files with 2 additions and 96 deletions

View File

@ -13,8 +13,7 @@ from lxml import etree
from datetime import datetime from datetime import datetime
APIKEY = "816cfe50ddeeb73c9987b85de5c19e71" APIKEY = "816cfe50ddeeb73c9987b85de5c19e71"
APIURL = "http://ws.audioscrobbler.com/2.0/?api_key="+APIKEY+"&" APIURL = "https://ws.audioscrobbler.com/2.0/?api_key="+APIKEY+"&"
AEPURL = "http://www.davethemoonman.com/lastfm/aep.php?format=txt&username="
config = configparser.RawConfigParser() config = configparser.RawConfigParser()
config.optionxform = str config.optionxform = str
@ -130,66 +129,6 @@ def now_playing(phenny, input):
now_playing.commands = ['np'] now_playing.commands = ['np']
def tasteometer(phenny, input):
input1 = input.group(2)
if not input1 or len(input1) == 0:
phenny.say("tasteometer: compares two users' musical taste")
phenny.say("syntax: .taste user1 user2")
return
input2 = input.group(3)
user1 = resolve_username(input1)
if not user1:
user1 = input1
user2 = resolve_username(input2)
if not user2:
user2 = input2
if not user2 or len(user2) == 0:
user2 = resolve_username(input.nick)
if not user2:
user2 = input.nick
try:
req = web.get("%smethod=tasteometer.compare&type1=user&type2=user&value1=%s&value2=%s" % (APIURL, web.quote(user1), web.quote(user2)))
except web.HTTPError as e:
if e.response.status_code == 400:
phenny.say("uhoh, someone doesn't exist on last.fm, perhaps they need to set user")
return
else:
phenny.say("uhoh. try again later, mmkay?")
return
root = etree.fromstring(req.encode('utf-8'))
score = root.xpath('comparison/result/score')
if len(score) == 0:
phenny.say("something isn't right. have those users scrobbled?")
return
score = float(score[0].text)
rating = ""
if score >= 0.9:
rating = "Super"
elif score >= 0.7:
rating = "Very High"
elif score >= 0.5:
rating = "High"
elif score >= 0.3:
rating = "Medium"
elif score >= 0.1:
rating = "Low"
else:
rating = "Very Low"
artists = root.xpath("comparison/result/artists/artist/name")
common_artists = ""
names = []
if len(artists) == 0:
common_artists = ". they don't have any artists in common."
else:
list(map(lambda a: names.append(a.text) ,artists))
common_artists = "and music they have in common includes: %s" % ", ".join(names)
phenny.say("%s's and %s's musical compatibility rating is %s %s" % (user1, user2, rating, common_artists))
tasteometer.rule = (['taste'], r'(\S+)(?:\s+(\S+))?')
def save_config(): def save_config():
configfile = open(config_filename, 'w') configfile = open(config_filename, 'w')
config.write(configfile) config.write(configfile)

View File

@ -6,7 +6,7 @@ author: mutantmonkey <mutantmonkey@mutantmonkey.in>
import re import re
import unittest import unittest
from mock import MagicMock, Mock from mock import MagicMock, Mock
from modules.lastfm import now_playing, tasteometer from modules.lastfm import now_playing
class TestLastfm(unittest.TestCase): class TestLastfm(unittest.TestCase):
@ -32,36 +32,3 @@ class TestLastfm(unittest.TestCase):
out = self.phenny.say.call_args[0][0] out = self.phenny.say.call_args[0][0]
m = re.match('^{0} listened to ".+" by .+ on .+ .*$'.format(self.user1), out, flags=re.UNICODE) m = re.match('^{0} listened to ".+" by .+ on .+ .*$'.format(self.user1), out, flags=re.UNICODE)
self.assertTrue(m) self.assertTrue(m)
def test_tasteometer(self):
def mock_group(x):
if x == 2:
return self.user1
else:
return self.user2
input = Mock(group=mock_group)
tasteometer(self.phenny, input)
out = self.phenny.say.call_args[0][0]
m = re.match("^{0}'s and {1}'s musical compatibility rating is .*"\
" they don't have any artists in common.$".
format(self.user1, self.user2), out, flags=re.UNICODE)
self.assertTrue(m)
def test_tasteometer_sender(self):
def mock_group(x):
if x == 2:
return self.user1
else:
return ''
input = Mock(group=mock_group)
input.nick = self.user2
tasteometer(self.phenny, input)
out = self.phenny.say.call_args[0][0]
m = re.match("^{0}'s and {1}'s musical compatibility rating is .*"\
" they don't have any artists in common.$".
format(self.user1, self.user2), out, flags=re.UNICODE)
self.assertTrue(m)