Standardised name saving between weather and lastfm
This commit is contained in:
parent
9ff3eda44b
commit
7eb9ff1c7f
1 changed files with 18 additions and 16 deletions
|
@ -1,7 +1,5 @@
|
||||||
# Upgraded with tables/caching by ChauffeR of #freebnc on irc.esper.net
|
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
|
||||||
|
|
||||||
@hook.command('l', autohelp=False)
|
@hook.command('l', autohelp=False)
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def lastfm(inp, nick='', say=None, db=None, bot=None):
|
def lastfm(inp, nick='', say=None, db=None, bot=None):
|
||||||
|
@ -15,23 +13,22 @@ def lastfm(inp, nick='', say=None, db=None, bot=None):
|
||||||
user = inp
|
user = inp
|
||||||
else:
|
else:
|
||||||
user = nick
|
user = nick
|
||||||
db.execute("create table if not exists lastfm(nick primary key, acc)")
|
|
||||||
sql = db.execute("select acc from lastfm where nick=lower(?)", (nick,)).fetchone();
|
|
||||||
api_url = "http://ws.audioscrobbler.com/2.0/?format=json"
|
api_url = "http://ws.audioscrobbler.com/2.0/?format=json"
|
||||||
|
|
||||||
|
dontsave = user.endswith(" dontsave")
|
||||||
|
if dontsave:
|
||||||
|
user = user[:-9].strip().lower()
|
||||||
|
|
||||||
if sql:
|
db.execute("create table if not exists lastfm(nick primary key, acc)")
|
||||||
if not inp: user = sql[0]
|
|
||||||
else:
|
if not user:
|
||||||
user = inp
|
user = db.execute("select acc from lastfm where nick=lower(?)",
|
||||||
db.execute("insert or replace into lastfm(nick,acc) values(?,?)", (nick.lower(), user))
|
(nick,)).fetchone()
|
||||||
db.commit()
|
if not user:
|
||||||
else:
|
notice(lastfm.__doc__)
|
||||||
if not inp: user = nick
|
return
|
||||||
else:
|
user = user[0]
|
||||||
user = inp
|
|
||||||
db.execute("insert or replace into lastfm(nick,acc) values(?,?)", (nick.lower(), user))
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
response = http.get_json(api_url, method="user.getrecenttracks",
|
response = http.get_json(api_url, method="user.getrecenttracks",
|
||||||
api_key=api_key, user=user, limit=1)
|
api_key=api_key, user=user, limit=1)
|
||||||
|
@ -69,5 +66,10 @@ def lastfm(inp, nick='', say=None, db=None, bot=None):
|
||||||
out += ' by "\x02%s\x0f"' % artist
|
out += ' by "\x02%s\x0f"' % artist
|
||||||
if album:
|
if album:
|
||||||
out += ' from the album "\x02%s\x0f"' % album
|
out += ' from the album "\x02%s\x0f"' % album
|
||||||
|
|
||||||
|
if inp and not dontsave:
|
||||||
|
db.execute("insert or replace into lastfm(nick, acc) values (?,?)",
|
||||||
|
(nick.lower(), user))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
Reference in a new issue