New lastfm module feature: AEP displaying.

master
Casey Link 2011-07-15 13:39:29 -04:00
parent bdb9f45730
commit 433daf8341
1 changed files with 34 additions and 1 deletions

View File

@ -15,6 +15,7 @@ from datetime import datetime
APIKEY = "b25b959554ed76058ac220b7b2e0a026" APIKEY = "b25b959554ed76058ac220b7b2e0a026"
APIURL = "http://ws.audioscrobbler.com/2.0/?api_key="+APIKEY+"&" APIURL = "http://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,6 +131,38 @@ def now_playing(phenny, input):
now_playing.commands = ['np'] now_playing.commands = ['np']
def aep(phenny, input):
# c/pied from now_playing, we should but this code in a function
# parse input and lookup lastfm user
nick = input.nick
user = ""
arg = input.group(2)
if arg == "help":
phenny.say("WTF is an AEP? see http://goo.gl/GBbx8")
return
if not arg or len(arg.strip()) == 0:
user = resolve_username(nick) # use the sender
if not user: #nick didnt resolve
user = nick
else: # use the argument
user = resolve_username(arg.strip())
if not user: # user didnt resolve
user = arg
user = user.strip()
try:
req = urlopen("%s%s" % (AEPURL, urlquote(user)))
except HTTPError, e:
phenny.say("uhoh. try again later, mmkay?")
return
result = req.read()
if "Bad Request" in result:
phenny.say("%s doesn't exist on last.fm, perhaps they need to set user (see lastfm-set)" % (user))
return
aep_val = result.split(":")[1]
phenny.say("%s has an AEP of %s" %(user, aep_val))
return
aep.commands = ['aep']
def tasteometer(phenny, input): def tasteometer(phenny, input):
input1 = input.group(2) input1 = input.group(2)
if not input1 or len(input1) == 0: if not input1 or len(input1) == 0: