From 6cc7554cd891449fbcd6bfba2a51bd21d3b1d935 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 13 Feb 2014 14:34:50 +1300 Subject: [PATCH] A dash of PEP-8 --- plugins/{coins.py => cryptocoins.py} | 5 +++-- plugins/dice.py | 14 +++++++------- plugins/domainr.py | 2 +- plugins/eightball.py | 2 +- plugins/namegen.py | 7 +++---- plugins/newegg.py | 14 +++++++------- plugins/password.py | 6 +++--- plugins/pre.py | 2 +- plugins/reddit.py | 12 ++++++------ plugins/twitter.py | 4 ++-- plugins/wolframalpha.py | 1 - 11 files changed, 34 insertions(+), 35 deletions(-) rename plugins/{coins.py => cryptocoins.py} (90%) diff --git a/plugins/coins.py b/plugins/cryptocoins.py similarity index 90% rename from plugins/coins.py rename to plugins/cryptocoins.py index bdb0e19..4973444 100644 --- a/plugins/coins.py +++ b/plugins/cryptocoins.py @@ -35,7 +35,8 @@ exchanges = { @hook.command("btc", autohelp=False) @hook.command(autohelp=False) def bitcoin(inp): - """bitcoin -- Gets current exchange rate for bitcoins from several exchanges, default is Blockchain. Supports MtGox, Bitpay, Coinbase and BitStamp.""" + """bitcoin -- Gets current exchange rate for bitcoins from several exchanges, default is Blockchain. + Supports MtGox, Bitpay, Coinbase and BitStamp.""" inp = inp.lower() if inp: @@ -58,4 +59,4 @@ def litecoin(inp, message=None): data = http.get_json("https://btc-e.com/api/2/ltc_usd/ticker") ticker = data['ticker'] message("Current: \x0307${:,.2f}\x0f - High: \x0307${:,.2f}\x0f" - " - Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} LTC".format(ticker['buy'], ticker['high'], ticker['low'], ticker['vol_cur'])) + " - Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} LTC".format(ticker['buy'], ticker['high'], ticker['low'], ticker['vol_cur'])) diff --git a/plugins/dice.py b/plugins/dice.py index 94e0f46..f748da6 100644 --- a/plugins/dice.py +++ b/plugins/dice.py @@ -49,7 +49,7 @@ def dice(inp): spec = whitespace_re.sub('', inp) if not valid_diceroll_re.match(spec): - return "Invalid diceroll" + return "Invalid dice roll" groups = sign_re.findall(spec) total = 0 @@ -73,13 +73,13 @@ def dice(inp): side = int(side) try: if count > 0: - dice = nrolls(count, side) - rolls += map(str, dice) - total += sum(dice) + d = nrolls(count, side) + rolls += map(str, d) + total += sum(d) else: - dice = nrolls(-count, side) - rolls += [str(-x) for x in dice] - total -= sum(dice) + d = nrolls(-count, side) + rolls += [str(-x) for x in d] + total -= sum(d) except OverflowError: return "Thanks for overflowing a float, jerk >:[" diff --git a/plugins/domainr.py b/plugins/domainr.py index 804d237..061ad3f 100644 --- a/plugins/domainr.py +++ b/plugins/domainr.py @@ -9,7 +9,7 @@ def domainr(inp): except (http.URLError, http.HTTPError) as e: return "Unable to get data for some reason. Try again later." if data['query'] == "": - return "An error occurrred: {status} - {message}".format(**data['error']) + return "An error occurred: {status} - {message}".format(**data['error']) domains = "" for domain in data['results']: domains += ("\x034" if domain['availability'] == "taken" else ( diff --git a/plugins/eightball.py b/plugins/eightball.py index 929a890..0e039fb 100644 --- a/plugins/eightball.py +++ b/plugins/eightball.py @@ -13,7 +13,7 @@ with open("plugins/data/8ball_responses.txt") as f: @hook.command('8ball') -def eightball(input, action=None): +def eightball(inp, action=None): """8ball -- The all knowing magic eight ball, in electronic form. Ask and it shall be answered!""" diff --git a/plugins/namegen.py b/plugins/namegen.py index f4ab7fe..0a95f36 100644 --- a/plugins/namegen.py +++ b/plugins/namegen.py @@ -1,4 +1,3 @@ -# Plugin by Lukeroge from util import hook, text, textgen import json import os @@ -10,13 +9,13 @@ GEN_DIR = "./plugins/data/name_files/" def get_generator(_json): data = json.loads(_json) return textgen.TextGenerator(data["templates"], - data["parts"], default_templates=data["default_templates"]) + data["parts"], default_templates=data["default_templates"]) @hook.command(autohelp=False) def namegen(inp, notice=None): - "namegen [generator] -- Generates some names using the chosen generator. " \ - "'namegen list' will display a list of all generators." + """namegen [generator] -- Generates some names using the chosen generator. + 'namegen list' will display a list of all generators.""" # clean up the input inp = inp.strip().lower() diff --git a/plugins/newegg.py b/plugins/newegg.py index 0a88286..76b2a70 100644 --- a/plugins/newegg.py +++ b/plugins/newegg.py @@ -21,11 +21,11 @@ def format_item(item, show_url=True): # format the rating nicely if it exists if not item["ReviewSummary"]["TotalReviews"] == "[]": rating = "Rated {}/5 ({} ratings)".format(item["ReviewSummary"]["Rating"], - item["ReviewSummary"]["TotalReviews"][1:-1]) + item["ReviewSummary"]["TotalReviews"][1:-1]) else: rating = "No Ratings" - if not item["FinalPrice"] == item["OriginalPrice"]: + if not item["FinalPrice"] == item["OriginalPrice"]: price = "{FinalPrice}, was {OriginalPrice}".format(**item) else: price = item["FinalPrice"] @@ -46,17 +46,17 @@ def format_item(item, show_url=True): if item["IsShellShockerItem"]: tags.append("\x02SHELL SHOCKER®\x02") - # join all the tags together in a comma seperated string ("tag1, tag2, tag3") + # join all the tags together in a comma separated string ("tag1, tag2, tag3") tag_text = u", ".join(tags) if show_url: # create the item URL and shorten it url = web.try_isgd(ITEM_URL.format(item["NeweggItemNumber"])) return u"\x02{}\x02 ({}) - {} - {} - {}".format(title, price, rating, - tag_text, url) + tag_text, url) else: return u"\x02{}\x02 ({}) - {} - {}".format(title, price, rating, - tag_text) + tag_text) ## HOOK FUNCTIONS @@ -80,8 +80,8 @@ def newegg(inp): # submit the search request r = http.get_json( - 'http://www.ows.newegg.com/Search.egg/Advanced', - post_data = json.dumps(request) + 'http://www.ows.newegg.com/Search.egg/Advanced', + post_data=json.dumps(request) ) # get the first result diff --git a/plugins/password.py b/plugins/password.py index 6878515..2187302 100644 --- a/plugins/password.py +++ b/plugins/password.py @@ -39,10 +39,10 @@ def password(inp, notice=None): if not okay: okay = okay + list(string.ascii_lowercase) - password = "" + pw = "" # generates password for x in range(length): - password = password + random.choice(okay) + pw = pw + random.choice(okay) - notice(password) + notice(pw) diff --git a/plugins/pre.py b/plugins/pre.py index 80aa77f..0e443f9 100644 --- a/plugins/pre.py +++ b/plugins/pre.py @@ -5,7 +5,7 @@ import datetime @hook.command("scene") @hook.command def pre(inp): - 'pre -- searches scene releases using orlydb.com' + """pre -- searches scene releases using orlydb.com""" try: h = http.get_html("http://orlydb.com/", q=inp) diff --git a/plugins/reddit.py b/plugins/reddit.py index 7b96a94..add83d1 100644 --- a/plugins/reddit.py +++ b/plugins/reddit.py @@ -52,7 +52,7 @@ def reddit(inp): data = data["data"]["children"] # get the requested/random post - if id_num != None: + if id_num is not None: try: item = data[id_num]["data"] except IndexError: @@ -64,14 +64,14 @@ def reddit(inp): item["title"] = text.truncate_str(item["title"], 50) item["link"] = short_url.format(item["id"]) - rawtime = datetime.fromtimestamp(int(item["created_utc"])) - item["timesince"] = timesince.timesince(rawtime) + raw_time = datetime.fromtimestamp(int(item["created_utc"])) + item["timesince"] = timesince.timesince(raw_time) if item["over_18"]: item["warning"] = " \x02NSFW\x02" else: item["warning"] = "" - return u'\x02{title} : {subreddit}\x02 - posted by \x02{author}\x02' \ - ' {timesince} ago - {ups} upvotes, {downs} downvotes -' \ - ' {link}{warning}'.format(**item) + return u"\x02{title} : {subreddit}\x02 - posted by \x02{author}\x02" \ + " {timesince} ago - {ups} upvotes, {downs} downvotes -" \ + " {link}{warning}".format(**item) diff --git a/plugins/twitter.py b/plugins/twitter.py index f0b2e52..2ea8ab8 100644 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -26,7 +26,7 @@ def get_api(bot): @hook.regex(*TWITTER_RE) def twitter_url(match, bot=None): tweet_id = match.group(1) - + api = get_api(bot) if not api: return @@ -46,7 +46,7 @@ def twitter_url(match, bot=None): time = timesince.timesince(tweet.created_at, datetime.utcnow()) return u"{}@\x02{}\x02 ({}): {} ({} ago)".format(prefix, user.screen_name, user.name, text, time) - + @hook.command("tw") @hook.command("twatter") diff --git a/plugins/wolframalpha.py b/plugins/wolframalpha.py index 0ade2bc..b20ffed 100644 --- a/plugins/wolframalpha.py +++ b/plugins/wolframalpha.py @@ -9,7 +9,6 @@ from util import hook, http, text, web @hook.command def wolframalpha(inp, bot=None): """wa -- Computes using Wolfram Alpha.""" - api_key = bot.config.get("api_keys", {}).get("wolframalpha", None) if not api_key: