From d6683b32f4b56e771fc5c85572282a6c5e575ed3 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 14 Feb 2014 17:03:08 +1300 Subject: [PATCH] PEP-8 --- plugins/core_ctcp.py | 1 - plugins/cryptocoins.py | 2 +- plugins/domainr.py | 4 ++-- plugins/encrypt.py | 2 +- plugins/factoids.py | 4 ++-- plugins/geoip.py | 1 - plugins/help.py | 4 ++-- plugins/horoscope.py | 2 +- plugins/imdb.py | 8 ++++---- plugins/imgur.py | 5 +++-- plugins/lastfm.py | 2 +- plugins/lyrics.py | 2 +- plugins/minecraft_bukget.py | 1 - plugins/minecraft_ping.py | 15 ++++++++------- plugins/notes.py | 4 ++-- plugins/potato.py | 2 +- plugins/quote.py | 2 +- plugins/rottentomatoes.py | 4 ++-- plugins/steam.py | 14 +++++++------- plugins/steam_calc.py | 4 ++-- plugins/tell.py | 2 +- plugins/tvdb.py | 2 +- plugins/utility.py | 33 ++++++++++++++++++++------------- plugins/wikipedia.py | 2 +- 24 files changed, 64 insertions(+), 58 deletions(-) diff --git a/plugins/core_ctcp.py b/plugins/core_ctcp.py index 23834db..3e7a200 100644 --- a/plugins/core_ctcp.py +++ b/plugins/core_ctcp.py @@ -3,7 +3,6 @@ import time from util import hook - # CTCP responses @hook.regex(r'^\x01VERSION\x01$') def ctcp_version(inp, notice=None): diff --git a/plugins/cryptocoins.py b/plugins/cryptocoins.py index a29fce1..fa51db7 100644 --- a/plugins/cryptocoins.py +++ b/plugins/cryptocoins.py @@ -17,7 +17,7 @@ exchanges = { data['return']['buy']['display'], data['return']['vol']['display']) }, - "coinbase":{ + "coinbase": { "api_url": "https://coinbase.com/api/v1/prices/spot_rate", "func": lambda data: u"Coinbase // Current: \x0307${:,.2f}\x0f".format(float(data['amount'])) }, diff --git a/plugins/domainr.py b/plugins/domainr.py index 061ad3f..e853bfa 100644 --- a/plugins/domainr.py +++ b/plugins/domainr.py @@ -13,6 +13,6 @@ def domainr(inp): domains = "" for domain in data['results']: domains += ("\x034" if domain['availability'] == "taken" else ( - "\x033" if domain['availability'] == "available" else "\x031")) + domain['domain'] + "\x0f" + domain[ - 'path'] + ", " + "\x033" if domain['availability'] == "available" else "\x031")) + domain['domain'] + "\x0f" + domain[ + 'path'] + ", " return "Domains: " + domains diff --git a/plugins/encrypt.py b/plugins/encrypt.py index 483ed48..23d6a6f 100644 --- a/plugins/encrypt.py +++ b/plugins/encrypt.py @@ -96,7 +96,7 @@ def decrypt(inp, bot=None, db=None, notice=None): # get the encoded IV from the database and decode it iv_encoded = db.execute("select iv from encryption where" - " encrypted=?", (text,)).fetchone()[0] + " encrypted=?", (text,)).fetchone()[0] iv = base64.b64decode(iv_encoded) # create AES cipher, decode text, decrypt text, and unpad it diff --git a/plugins/factoids.py b/plugins/factoids.py index 3811c94..7468b66 100644 --- a/plugins/factoids.py +++ b/plugins/factoids.py @@ -132,8 +132,8 @@ def factoid(inp, message=None, db=None, bot=None, action=None, conn=None, input= if data.startswith(""): code = data[4:].strip() variables = 'input="""{}"""; nick="{}"; chan="{}"; bot_nick="{}";'.format(arguments.replace('"', '\\"'), - input.nick, input.chan, - input.conn.nick) + input.nick, input.chan, + input.conn.nick) result = pyexec.eval_py(variables + code) else: result = data diff --git a/plugins/geoip.py b/plugins/geoip.py index 003d915..e46cde9 100644 --- a/plugins/geoip.py +++ b/plugins/geoip.py @@ -8,7 +8,6 @@ import pygeoip from util import hook, http - # load region database with open("./plugins/data/geoip_regions.json", "rb") as f: regions = json.loads(f.read()) diff --git a/plugins/help.py b/plugins/help.py index 805ab15..d2b3d2e 100644 --- a/plugins/help.py +++ b/plugins/help.py @@ -3,8 +3,8 @@ import re from util import hook -@hook.command(autohelp=False) -def help(inp, notice=None, conn=None, bot=None): +@hook.command("help", autohelp=False) +def help_command(inp, notice=None, conn=None, bot=None): """help -- Gives a list of commands/help for a command.""" funcs = {} diff --git a/plugins/horoscope.py b/plugins/horoscope.py index 51d1dd6..74b12e0 100644 --- a/plugins/horoscope.py +++ b/plugins/horoscope.py @@ -50,7 +50,7 @@ def horoscope(inp, db=None, notice=None, nick=None): if inp and not dontsave: db.execute("insert or replace into horoscope(nick, sign) values (?,?)", - (nick.lower(), sign)) + (nick.lower(), sign)) db.commit() return result diff --git a/plugins/imdb.py b/plugins/imdb.py index a577a9d..0272248 100644 --- a/plugins/imdb.py +++ b/plugins/imdb.py @@ -39,10 +39,10 @@ def imdb(inp): @hook.regex(*imdb_re) def imdb_url(match): - id = match.group(4).split('/')[-1] - if id == "": - id = match.group(4).split('/')[-2] - content = http.get_json("http://www.omdbapi.com/", i=id) + imdb_id = match.group(4).split('/')[-1] + if imdb_id == "": + imdb_id = match.group(4).split('/')[-2] + content = http.get_json("http://www.omdbapi.com/", i=imdb_id) if content.get('Error', None) == 'Movie not found!': return 'Movie not found!' elif content['Response'] == 'True': diff --git a/plugins/imgur.py b/plugins/imgur.py index 603f106..320bc6e 100644 --- a/plugins/imgur.py +++ b/plugins/imgur.py @@ -19,7 +19,8 @@ def is_valid(data): @hook.command(autohelp=False) def imgur(inp): - """imgur [subreddit] -- Gets the first page of imgur images from [subreddit] and returns a link to them. If [subreddit] is undefined, return any imgur images""" + """imgur [subreddit] -- Gets the first page of imgur images from [subreddit] and returns a link to them. + If [subreddit] is undefined, return any imgur images""" if inp: # see if the input ends with "nsfw" show_nsfw = inp.endswith(" nsfw") @@ -50,7 +51,7 @@ def imgur(inp): items = [] headers = { - "Authorization": "Client-ID b5d127e6941b07a" + "Authorization": "Client-ID b5d127e6941b07a" } # loop over the list of posts diff --git a/plugins/lastfm.py b/plugins/lastfm.py index f126dbe..87ca6e7 100644 --- a/plugins/lastfm.py +++ b/plugins/lastfm.py @@ -77,7 +77,7 @@ def lastfm(inp, nick='', db=None, bot=None, notice=None): if inp and not dontsave: db.execute("insert or replace into lastfm(nick, acc) values (?,?)", - (nick.lower(), user)) + (nick.lower(), user)) db.commit() return out diff --git a/plugins/lyrics.py b/plugins/lyrics.py index 6a226e8..eabb84a 100644 --- a/plugins/lyrics.py +++ b/plugins/lyrics.py @@ -38,6 +38,6 @@ def lyrics(inp): else: lyricsum = " / ".join(lyricsum.strip().split("\n")[0:4]) # truncate, format return "\x02{}\x02 by \x02{}\x02 {}{} - {}".format(title, artist, web.try_isgd(link), pasteurl, - lyricsum[:-3]) + lyricsum[:-3]) else: return "No song results. " + url + inp.replace(" ", "+") diff --git a/plugins/minecraft_bukget.py b/plugins/minecraft_bukget.py index 352d5d8..496f169 100644 --- a/plugins/minecraft_bukget.py +++ b/plugins/minecraft_bukget.py @@ -132,7 +132,6 @@ def bukget(inp, reply=None, message=None): message(line_b) - @hook.command(autohelp=None) def randomplugin(inp, reply=None, message=None): """randomplugin - Gets a random plugin from dev.bukkit.org""" diff --git a/plugins/minecraft_ping.py b/plugins/minecraft_ping.py index ccca77b..d746f44 100644 --- a/plugins/minecraft_ping.py +++ b/plugins/minecraft_ping.py @@ -15,9 +15,9 @@ except ImportError: mccolors = [u"\x0300,\xa7f", u"\x0301,\xa70", u"\x0302,\xa71", u"\x0303,\xa72", u"\x0304,\xa7c", u"\x0305,\xa74", - u"\x0306,\xa75", u"\x0307,\xa76", u"\x0308,\xa7e", u"\x0309,\xa7a", u"\x0310,\xa73", u"\x0311,\xa7b", - u"\x0312,\xa71", u"\x0313,\xa7d", u"\x0314,\xa78", u"\x0315,\xa77", u"\x02,\xa7l", u"\x0310,\xa79", - u"\x09,\xa7o", u"\x13,\xa7m", u"\x0f,\xa7r", u"\x15,\xa7n"] + u"\x0306,\xa75", u"\x0307,\xa76", u"\x0308,\xa7e", u"\x0309,\xa7a", u"\x0310,\xa73", u"\x0311,\xa7b", + u"\x0312,\xa71", u"\x0313,\xa7d", u"\x0314,\xa78", u"\x0315,\xa77", u"\x02,\xa7l", u"\x0310,\xa79", + u"\x09,\xa7o", u"\x13,\xa7m", u"\x0f,\xa7r", u"\x15,\xa7n"] def mc_color_format(motd): @@ -77,11 +77,12 @@ def mcping_modern(host, port): try: version = data["version"]["name"] desc = data["description"] - max = data["players"]["max"] + max_players = data["players"]["max"] online = data["players"]["online"] except Exception as e: return "Invalid data: {}; error: {}".format(data, e) - return mc_color_format(u"{}\x0f - {}\x0f - {}/{} players *".format(desc, version, online, max)).replace("\n", u"\x0f - ") + return mc_color_format(u"{}\x0f - {}\x0f - {}/{} players *".format(desc, version, online, + max_players)).replace("\n", u"\x0f - ") def mcping_legacy(host, port): @@ -102,7 +103,8 @@ def mcping_legacy(host, port): message = u"{} - {}/{} players".format(mc_color_format(data[0]), data[1], data[2]) else: # decoded data, server is using new format - message = u"{} \x0f- {} - {}/{} players".format(mc_color_format(data[3]), mc_color_format(data[2]), data[4], data[5]) + message = u"{} \x0f- {} - {}/{} players".format(mc_color_format(data[3]), + mc_color_format(data[2]), data[4], data[5]) sock.close() return message @@ -174,7 +176,6 @@ def mcping(inp): # return e.args[0] # - try: return mcping_modern(host, port) except: diff --git a/plugins/notes.py b/plugins/notes.py index 63a671c..129b7d5 100644 --- a/plugins/notes.py +++ b/plugins/notes.py @@ -46,14 +46,14 @@ def db_getall(db, nick, limit=-1): """, (nick, limit)) -def db_get(db, nick, id): +def db_get(db, nick, note_id): return db.execute(""" select added, text from todos where lower(user) = lower(?) order by added desc limit 1 offset ? - """, (nick, id)).fetchone() + """, (nick, note_id)).fetchone() def db_del(db, nick, limit='all'): diff --git a/plugins/potato.py b/plugins/potato.py index dbef4ec..9987e18 100644 --- a/plugins/potato.py +++ b/plugins/potato.py @@ -39,7 +39,7 @@ potatoes = ['AC Belmont', 'AC Blue Pride', 'AC Brador', 'AC Chaleur', 'AC Domino @hook.command -def potato(inp, action=None, input=None): +def potato(inp, action=None): """potato - Makes a tasty little potato.""" inp = inp.strip() diff --git a/plugins/quote.py b/plugins/quote.py index 1af8874..6beefc5 100644 --- a/plugins/quote.py +++ b/plugins/quote.py @@ -9,7 +9,7 @@ def format_quote(q, num, n_quotes): """Returns a formatted string of a quote""" ctime, nick, msg = q return "[{}/{}] <{}> {}".format(num, n_quotes, - nick, msg) + nick, msg) def create_table_if_not_exists(db): diff --git a/plugins/rottentomatoes.py b/plugins/rottentomatoes.py index fae99dd..2d7af38 100644 --- a/plugins/rottentomatoes.py +++ b/plugins/rottentomatoes.py @@ -21,7 +21,7 @@ def rottentomatoes(inp, bot=None): movie = results['movies'][0] title = movie['title'] - id = movie['id'] + movie_id = movie['id'] critics_score = movie['ratings']['critics_score'] audience_score = movie['ratings']['audience_score'] url = movie['links']['alternate'] @@ -29,7 +29,7 @@ def rottentomatoes(inp, bot=None): if critics_score == -1: return - reviews = http.get_json(movie_reviews_url % id, apikey=api_key, review_type='all') + reviews = http.get_json(movie_reviews_url % movie_id, apikey=api_key, review_type='all') review_count = reviews['total'] fresh = critics_score * review_count / 100 diff --git a/plugins/steam.py b/plugins/steam.py index 3bc06c2..f3814db 100644 --- a/plugins/steam.py +++ b/plugins/steam.py @@ -30,11 +30,11 @@ def get_steam_info(url): break # find the next element directly after the tag - next = b.nextSibling - if next: + next_element = b.nextSibling + if next_element: # if the element is some text - if isinstance(next, NavigableString): - text = next.string.strip() + if isinstance(next_element, NavigableString): + text = next_element.string.strip() if text: # we found valid text, save it and continue the loop data[title] = text @@ -44,11 +44,11 @@ def get_steam_info(url): # useless spaces or tabs between the and tags. # so we find the next tag and carry on to the next # bit of code below - next = next.find_next('a', href=True) + next_element = next_element.find_next('a', href=True) # if the element is an tag - if isinstance(next, Tag) and next.name == 'a': - text = next.string.strip() + if isinstance(next_element, Tag) and next_element.name == 'a': + text = next_element.string.strip() if text: # we found valid text (in the tag), # save it and continue the loop diff --git a/plugins/steam_calc.py b/plugins/steam_calc.py index 2aef985..30b656e 100644 --- a/plugins/steam_calc.py +++ b/plugins/steam_calc.py @@ -99,8 +99,8 @@ def steamcalc(inp, reply=None): data["size"] = "{0:.1f}".format(total_size) reply("{name} ({state}) has {games} games with a total value of ${value}" - " and a total size of {size}GB! The average metascore for these" - " games is {average_metascore}.".format(**data)) + " and a total size of {size}GB! The average metascore for these" + " games is {average_metascore}.".format(**data)) if do_refresh: refresh_data(name) diff --git a/plugins/tell.py b/plugins/tell.py index d2e7ffc..67f7ec3 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -38,7 +38,7 @@ def tellinput(paraml, input=None, notice=None, db=None, bot=None, nick=None, con reltime = timesince.timesince(time) reply = "{} sent you a message {} ago from {}: {}".format(user_from, reltime, chan, - message) + message) if len(tells) > 1: reply += " (+{} more, {}showtells to view)".format(len(tells) - 1, conn.conf["command_prefix"]) diff --git a/plugins/tvdb.py b/plugins/tvdb.py index 6a78502..55914ca 100644 --- a/plugins/tvdb.py +++ b/plugins/tvdb.py @@ -44,7 +44,7 @@ def get_episodes_for_series(series_name, api_key): try: series = get_zipped_xml(base_url + '%s/series/%s/all/en.zip' % - (api_key, series_id), path="en.xml") + (api_key, series_id), path="en.xml") except URLError: res["error"] = "Error contacting thetvdb.com." return res diff --git a/plugins/utility.py b/plugins/utility.py index 6a558f6..b0afa5b 100644 --- a/plugins/utility.py +++ b/plugins/utility.py @@ -8,17 +8,17 @@ from util import hook, text # variables colors = collections.OrderedDict([ - ('red', '\x0304'), - ('orange', '\x0307'), - ('yellow', '\x0308'), - ('green', '\x0309'), - ('cyan', '\x0303'), - ('ltblue', '\x0310'), - ('rylblue', '\x0312'), - ('blue', '\x0302'), - ('magenta', '\x0306'), - ('pink', '\x0313'), - ('maroon', '\x0305') + ('red', '\x0304'), + ('orange', '\x0307'), + ('yellow', '\x0308'), + ('green', '\x0309'), + ('cyan', '\x0303'), + ('ltblue', '\x0310'), + ('rylblue', '\x0312'), + ('blue', '\x0302'), + ('magenta', '\x0306'), + ('pink', '\x0313'), + ('maroon', '\x0305') ]) # helper functions @@ -29,6 +29,7 @@ strip_re = re.compile("(\x03|\x02|\x1f)(?:,?\d{1,2}(?:,\d{1,2})?)?", re.UNICODE) def strip(string): return strip_re.sub('', string) + # basic text tools @@ -63,6 +64,7 @@ def swapcase(inp): """swapcase -- Swaps the capitalization of .""" return inp.swapcase() + # encoding @@ -116,6 +118,7 @@ def escape(inp): except Exception as e: return "Error: {}".format(e) + # length @@ -124,6 +127,7 @@ def length(inp): """length -- gets the length of """ return "The length of that string is {} characters.".format(len(inp)) + # reverse @@ -132,15 +136,17 @@ def reverse(inp): """reverse -- reverses .""" return inp[::-1] + # hashing -@hook.command -def hash(inp): +@hook.command("hash") +def hash_command(inp): """hash -- Returns hashes of .""" return ', '.join(x + ": " + getattr(hashlib, x)(inp).hexdigest() for x in ['md5', 'sha1', 'sha256']) + # novelty @@ -149,6 +155,7 @@ def munge(inp): """munge -- Munges up .""" return text.munge(inp) + # colors - based on code by Reece Selwood - diff --git a/plugins/wikipedia.py b/plugins/wikipedia.py index 58984cc..6b3827a 100644 --- a/plugins/wikipedia.py +++ b/plugins/wikipedia.py @@ -30,7 +30,7 @@ def wiki(inp): def extract(item): return [item.find(ns + x).text for x in - ('Text', 'Description', 'Url')] + ('Text', 'Description', 'Url')] title, desc, url = extract(items[0])