From e12e7721da009798c5ed5f12e52f76e9d651992e Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Wed, 5 Sep 2012 07:52:03 +1200 Subject: [PATCH] PEP8, various other tweaks --- plugins/admin.py | 2 -- plugins/fortune.py | 1 - plugins/gcalc.py | 4 +--- plugins/help.py | 5 ++--- plugins/lastfm.py | 24 +++++++++++++----------- plugins/lmgtfy.py | 9 +++------ plugins/urlparse.py | 2 +- plugins/util/execute.py | 4 ++-- plugins/util/http.py | 2 +- plugins/util/text.py | 6 ++++-- plugins/util/web.py | 4 ++-- 11 files changed, 29 insertions(+), 34 deletions(-) diff --git a/plugins/admin.py b/plugins/admin.py index 9adcac9..1e23e6d 100755 --- a/plugins/admin.py +++ b/plugins/admin.py @@ -1,8 +1,6 @@ -# Plugin made by iloveportalz0r, TheNoodle, Lukeroge and neersighted from util import hook import os import re -import sys import json import time import subprocess diff --git a/plugins/fortune.py b/plugins/fortune.py index 5b24ede..3d458ab 100755 --- a/plugins/fortune.py +++ b/plugins/fortune.py @@ -1,5 +1,4 @@ from util import hook -import re import random with open("plugins/data/fortunes.txt") as f: diff --git a/plugins/gcalc.py b/plugins/gcalc.py index f8035cd..59c8dbd 100755 --- a/plugins/gcalc.py +++ b/plugins/gcalc.py @@ -1,6 +1,4 @@ -import re - -from util import hook, http, misc +from util import hook, http from bs4 import BeautifulSoup diff --git a/plugins/help.py b/plugins/help.py index fbb36a0..cbba8c7 100755 --- a/plugins/help.py +++ b/plugins/help.py @@ -26,7 +26,6 @@ def help(inp, say=None, notice=None, input=None, conn=None, bot=None): commands = dict((value, key) for key, value in funcs.iteritems()) if not inp: - length = 0 out = ["", ""] well = [] for x in commands: @@ -41,8 +40,8 @@ def help(inp, say=None, notice=None, input=None, conn=None, bot=None): notice("Commands I recognise: " + out[0][1:]) if out[1]: notice(out[1][1:]) - notice("For detailed help, do '.help ' where "\ - "is the name of the command you want help for.") + notice("For detailed help, do '%shelp ' where "\ + "is the name of the command you want help for." % conn.conf["command_prefix"]) else: if inp in commands: diff --git a/plugins/lastfm.py b/plugins/lastfm.py index b55d99b..c075a65 100755 --- a/plugins/lastfm.py +++ b/plugins/lastfm.py @@ -1,22 +1,24 @@ from util import hook, http, timesince from datetime import datetime +api_url = "http://ws.audioscrobbler.com/2.0/?format=json" + + @hook.command('l', 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, notice=None): "lastfm [user] [dontsave] -- Displays the now playing (or last played)" \ " track of LastFM user [user]." api_key = bot.config.get("api_keys", {}).get("lastfm") if not api_key: return "error: no api key set" - user = inp - - api_url = "http://ws.audioscrobbler.com/2.0/?format=json" - - dontsave = user.endswith(" dontsave") + # check if the user asked us not to save his details + dontsave = inp.endswith(" dontsave") if dontsave: - user = user[:-9].strip().lower() + user = inp[:-9].strip().lower() + else: + user = inp db.execute("create table if not exists lastfm(nick primary key, acc)") @@ -36,7 +38,7 @@ def lastfm(inp, nick='', say=None, db=None, bot=None): if not "track" in response["recenttracks"] or len(response["recenttracks"]["track"]) == 0: return 'No recent tracks for user "%s" found.' % user - + tracks = response["recenttracks"]["track"] if type(tracks) == list: @@ -54,7 +56,7 @@ def lastfm(inp, nick='', say=None, db=None, bot=None): time_listened = datetime.fromtimestamp(int(track["date"]["uts"])) time_since = timesince.timesince(time_listened) ending = ' (%s ago)' % time_since - + else: return "error: could not parse track listing" @@ -67,10 +69,10 @@ def lastfm(inp, nick='', say=None, db=None, bot=None): out += " by \x02%s\x0f" % artist if album: out += " from the album \x02%s\x0f" % album - + # append ending based on what type it was out += ending - + if inp and not dontsave: db.execute("insert or replace into lastfm(nick, acc) values (?,?)", (nick.lower(), user)) diff --git a/plugins/lmgtfy.py b/plugins/lmgtfy.py index 0ad561b..a15bf4c 100644 --- a/plugins/lmgtfy.py +++ b/plugins/lmgtfy.py @@ -1,7 +1,4 @@ - -from util import hook -from util.web import isgd -from urllib import quote_plus +from util import hook, web, http @hook.command('gfy') @@ -9,5 +6,5 @@ from urllib import quote_plus def lmgtfy(inp, bot=None): "lmgtfy [phrase] - Posts a google link for the specified phrase" - url = "http://lmgtfy.com/?q=%s" % quote_plus(inp) - return isgd(url, api_user, api_key) \ No newline at end of file + url = "http://lmgtfy.com/?q=%s" % http.quote_plus(inp) + return web.isgd(url) diff --git a/plugins/urlparse.py b/plugins/urlparse.py index 7bf5abc..4ad6dfd 100755 --- a/plugins/urlparse.py +++ b/plugins/urlparse.py @@ -18,4 +18,4 @@ def title(inp): title = http.unescape(title) - return title \ No newline at end of file + return title diff --git a/plugins/util/execute.py b/plugins/util/execute.py index 9eb2321..3043f9a 100644 --- a/plugins/util/execute.py +++ b/plugins/util/execute.py @@ -14,8 +14,8 @@ def eval_py(code, paste_multiline=True): status = "Python error: " else: status = "Code executed sucessfully: " - + if "\n" in output and paste_multiline: return status + web.haste(output) else: - return output \ No newline at end of file + return output diff --git a/plugins/util/http.py b/plugins/util/http.py index 58cddf8..d90359b 100755 --- a/plugins/util/http.py +++ b/plugins/util/http.py @@ -103,4 +103,4 @@ def quote(s): def unescape(s): if not s.strip(): return s - return html.fromstring(s).text_content() \ No newline at end of file + return html.fromstring(s).text_content() diff --git a/plugins/util/text.py b/plugins/util/text.py index 8857e8f..5047561 100755 --- a/plugins/util/text.py +++ b/plugins/util/text.py @@ -104,8 +104,10 @@ def get_text_list(list_, last_word='or'): >>> get_text_list([]) u'' """ - if len(list_) == 0: return '' - if len(list_) == 1: return list_[0] + if len(list_) == 0: + return '' + if len(list_) == 1: + return list_[0] return '%s %s %s' % ( # Translators: This string is used as a separator between list elements (', ').join([i for i in list_][:-1]), diff --git a/plugins/util/web.py b/plugins/util/web.py index 193f2cf..bed1e68 100755 --- a/plugins/util/web.py +++ b/plugins/util/web.py @@ -10,7 +10,7 @@ paste_url = "http://paste.dmptr.com" def isgd(url): """ shortens a URL with the is.gd PAI """ url = urlnorm.normalize(url.encode('utf-8')) - params = urllib.urlencode({'format': 'simple', 'url': url}) + params = urllib.urlencode({'format': 'simple', 'url': url}) return http.get("http://is.gd/create.php?%s" % params) @@ -19,4 +19,4 @@ def haste(text): request = urllib2.Request(paste_url + "/documents", text) response = urllib2.urlopen(request) data = json.loads(response.read()) - return("%s/%s.txt" % (paste_url, data['key'])) \ No newline at end of file + return("%s/%s.txt" % (paste_url, data['key']))