From 0aa2185edeae2129e3297fcaafcd5d72696e68e2 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Thu, 5 Sep 2013 10:11:18 +0800 Subject: [PATCH] more .format. --- plugins/lastfm.py | 12 ++++++------ plugins/lmgtfy.py | 2 +- plugins/lyrics.py | 10 +++++----- plugins/metacritic.py | 9 ++++----- plugins/minecraft_bukkit.py | 20 +++++++------------- plugins/minecraft_items.py | 8 ++++---- plugins/minecraft_wiki.py | 2 +- plugins/mlia.py | 4 ++-- plugins/namegen.py | 2 +- plugins/ping.py | 2 +- plugins/potato.py | 4 ++-- plugins/puush.py | 2 +- plugins/quote.py | 9 ++++----- plugins/reddit.py | 2 +- plugins/snopes.py | 2 +- 15 files changed, 41 insertions(+), 49 deletions(-) diff --git a/plugins/lastfm.py b/plugins/lastfm.py index 5436409..4f56ee3 100755 --- a/plugins/lastfm.py +++ b/plugins/lastfm.py @@ -34,10 +34,10 @@ def lastfm(inp, nick='', db=None, bot=None, notice=None): api_key=api_key, user=user, limit=1) if 'error' in response: - return "Error: %s." % response["message"] + return "Error: {}.".format(response["message"]) if not "track" in response["recenttracks"] or len(response["recenttracks"]["track"]) == 0: - return 'No recent tracks for user "%s" found.' % user + return 'No recent tracks for user "{}" found.'.format(user) tracks = response["recenttracks"]["track"] @@ -55,7 +55,7 @@ def lastfm(inp, nick='', db=None, bot=None, notice=None): # lets see how long ago they listened to it time_listened = datetime.fromtimestamp(int(track["date"]["uts"])) time_since = timesince.timesince(time_listened) - ending = ' (%s ago)' % time_since + ending = ' ({} ago)'.format(time_since) else: return "error: could not parse track listing" @@ -64,11 +64,11 @@ def lastfm(inp, nick='', db=None, bot=None, notice=None): album = track["album"]["#text"] artist = track["artist"]["#text"] - out = '%s %s "%s"' % (user, status, title) + out = '{} {} "{}"'.format(user, status, title) if artist: - out += " by \x02%s\x0f" % artist + out += " by \x02{}\x0f".format(artist) if album: - out += " from the album \x02%s\x0f" % album + out += " from the album \x02{}\x0f".format(album) # append ending based on what type it was out += ending diff --git a/plugins/lmgtfy.py b/plugins/lmgtfy.py index 5d10823..c8dcee3 100644 --- a/plugins/lmgtfy.py +++ b/plugins/lmgtfy.py @@ -6,7 +6,7 @@ from util import hook, web, http def lmgtfy(inp): """lmgtfy [phrase] - Posts a google link for the specified phrase""" - link = "http://lmgtfy.com/?q=%s" % http.quote_plus(inp) + link = "http://lmgtfy.com/?q={}".format(http.quote_plus(inp)) try: return web.isgd(link) diff --git a/plugins/lyrics.py b/plugins/lyrics.py index 1456c36..72a8351 100644 --- a/plugins/lyrics.py +++ b/plugins/lyrics.py @@ -29,7 +29,7 @@ def lyrics(inp): lyrics = newsoup.find('div', {'style': 'margin-left:10px;margin-right:10px;'}).text.strip() pasteurl = " " + web.haste(lyrics) except Exception as e: - pasteurl = " (\x02Unable to paste lyrics\x02 [%s])" % str(e) + pasteurl = " (\x02Unable to paste lyrics\x02 [{}])".format(str(e)) else: pasteurl = "" artist = div.find('b').text.title() @@ -39,10 +39,10 @@ def lyrics(inp): spurl = "" lyricsum = div.find('div').text if "\r\n" in lyricsum.strip(): - lyricsum = " / ".join(lyricsum.strip().split("\r\n")[0:4]) # truncate, format + lyricsum = " / ".join(lyricsum.strip().split("\r\n")[0:4]) # truncate, format else: - lyricsum = " / ".join(lyricsum.strip().split("\n")[0:4]) # truncate, format - return "\x02%s\x02 by \x02%s\x02 %s%s%s - %s" % ( - title, artist, web.try_isgd(link), spurl, pasteurl, lyricsum[:-3]) + lyricsum = " / ".join(lyricsum.strip().split("\n")[0:4]) # truncate, format + return "\x02{}\x02 by \x02{}\x02 {}{}{} - {}".format(title, artist, web.try_isgd(link), spurl, pasteurl, + lyricsum[:-3]) else: return "No song results. " + url + inp.replace(" ", "+") diff --git a/plugins/metacritic.py b/plugins/metacritic.py index 5679529..0168230 100755 --- a/plugins/metacritic.py +++ b/plugins/metacritic.py @@ -36,7 +36,7 @@ def metacritic(inp): title_safe = http.quote_plus(title) - url = 'http://www.metacritic.com/search/%s/%s/results' % (cat, title_safe) + url = 'http://www.metacritic.com/search/{}/{}/results'.format(cat, title_safe) try: doc = http.get_html(url) @@ -132,7 +132,6 @@ def metacritic(inp): except IndexError: score = None - return '[%s] %s - \x02%s/100\x02, %s - %s' % (plat.upper(), name, - score or 'no score', - 'release: \x02%s\x02' % release if release else 'unreleased', - link) + return '[{}] {} - \x02{}/100\x02, {} - {}'.format(plat.upper(), name, score or 'no score', + 'release: \x02%s\x02' % release if release else 'unreleased', + link) diff --git a/plugins/minecraft_bukkit.py b/plugins/minecraft_bukkit.py index 9bc8201..ad1a38c 100644 --- a/plugins/minecraft_bukkit.py +++ b/plugins/minecraft_bukkit.py @@ -27,13 +27,10 @@ def randombukkitplugin(inp, reply=None): bukkitver = ", ".join(data['versions'][0]['game_versions']) link = web.isgd(data['versions'][0]['link']) if description != "": - reply("\x02%s\x02, by \x02%s\x02 - %s - (%s) \x02%s" - % (name, authors, description, stage, url)) + reply("\x02{}\x02, by \x02{}\x02 - {} - ({}) \x02{}".format(name, authors, description, stage, url)) else: - reply("\x02%s\x02, by \x02%s\x02 (%s) \x02%s" - % (name, authors, stage, url)) - reply("Last release: \x02v%s\x02 for \x02%s\x02 at %s \x02%s\x02" - % (lastVersion, bukkitver, lastUpdate, link)) + reply("\x02{}\x02, by \x02{}\x02 ({}) \x02{}".format(name, authors, stage, url)) + reply("Last release: \x02v{}\x02 for \x02{}\x02 at {} \x02{}\x02".format(lastVersion, bukkitver, lastUpdate, link)) @hook.command('bplugin') @@ -57,13 +54,10 @@ def bukkitplugin(inp, reply=None): bukkitver = ", ".join(data['versions'][0]['game_versions']) link = web.isgd(data['versions'][0]['link']) if description != "": - reply("\x02%s\x02, by \x02%s\x02 - %s - (%s) \x02%s" - % (name, authors, description, stage, url)) + reply("\x02{}\x02, by \x02{}\x02 - {} - ({}) \x02{}".format(name, authors, description, stage, url)) else: - reply("\x02%s\x02, by \x02%s\x02 (%s) \x02%s" - % (name, authors, stage, url)) - reply("Last release: \x02v%s\x02 for \x02%s\x02 at %s \x02%s\x02" - % (lastVersion, bukkitver, lastUpdate, link)) + reply("\x02{}\x02, by \x02{}\x02 ({}) \x02{}".format(name, authors, stage, url)) + reply("Last release: \x02v{}\x02 for \x02{}\x02 at {} \x02{}\x02".format(lastVersion, bukkitver, lastUpdate, link)) def getplugininfo(inp): @@ -75,5 +69,5 @@ def getplugininfo(inp): data = http.get_json("http://api.bukget.org/3/plugins/bukkit/%s/" % slug) except HTTPError as e: - return "Got error: %s" % e + return "Got error: {}".format(e) return data diff --git a/plugins/minecraft_items.py b/plugins/minecraft_items.py index ac64e05..97a6420 100755 --- a/plugins/minecraft_items.py +++ b/plugins/minecraft_items.py @@ -61,16 +61,16 @@ def mcitem(input, reply=None): for id, name in ids: if input == id: - results = ["\x02[%s]\x02 %s" % (id, name)] + results = ["\x02[{}]\x02 {}".format(id, name)] break elif input in name.lower(): - results.append("\x02[%s]\x02 %s" % (id, name)) + results.append("\x02[{}]\x02 {}".format(id, name)) if not results: return "No matches found." if len(results) > 12: - reply("There are too many options, please narrow your search. (%s)" % len(results)) + reply("There are too many options, please narrow your search. ({})".format(str(len(results)))) return out = ", ".join(results) @@ -91,7 +91,7 @@ def mcrecipe(input, reply=None): return "No matches found." if len(results) > 3: - reply("There are too many options, please narrow your search. (%s)" % len(results)) + reply("There are too many options, please narrow your search. ({})".format(len(results))) return for result in results: diff --git a/plugins/minecraft_wiki.py b/plugins/minecraft_wiki.py index a2b4cf3..210c3f4 100755 --- a/plugins/minecraft_wiki.py +++ b/plugins/minecraft_wiki.py @@ -24,6 +24,6 @@ def mcwiki(inp): summary = " ".join(p.text_content().splitlines()) summary = re.sub("\[\d+\]", "", summary) summary = text.truncate_str(summary, 200) - return "%s :: %s" % (summary, url) + return "{} :: {}".format(summary, url) return "Unknown Error." diff --git a/plugins/mlia.py b/plugins/mlia.py index ad3de91..c155a3e 100644 --- a/plugins/mlia.py +++ b/plugins/mlia.py @@ -9,7 +9,7 @@ mlia_cache = [] def refresh_cache(): """gets a page of random MLIAs and puts them into a dictionary """ - url = 'http://mylifeisaverage.com/%s' % random.randint(1, 11000) + url = 'http://mylifeisaverage.com/{}'.format(random.randint(1, 11000)) soup = http.get_soup(url) for story in soup.find_all('div', {'class': 'story '}): @@ -27,7 +27,7 @@ def mlia(inp, reply=None): # grab the last item in the mlia cache and remove it id, text = mlia_cache.pop() # reply with the mlia we grabbed - reply('(%s) %s' % (id, text)) + reply('({}) {}'.format(id, text)) # refresh mlia cache if its getting empty if len(mlia_cache) < 3: refresh_cache() diff --git a/plugins/namegen.py b/plugins/namegen.py index a761924..6e081c0 100755 --- a/plugins/namegen.py +++ b/plugins/namegen.py @@ -36,7 +36,7 @@ class NameGenerator(object): for name_part in name_parts: part = random.choice(self.parts[name_part]) - name = name.replace("{%s}" % name_part, part) + name = name.replace("{{}}".format(name_part), part) return name diff --git a/plugins/ping.py b/plugins/ping.py index 549906b..746ea05 100755 --- a/plugins/ping.py +++ b/plugins/ping.py @@ -31,7 +31,7 @@ def ping(inp, reply=None): # I assume it's no longer needed with the way we run the process # host = re.sub(r'([^\s\w\.])+', '', host) - reply("Attempting to ping %s %s times..." % (host, count)) + reply("Attempting to ping {} {} times...".format(host, count)) pingcmd = subprocess.check_output(["ping", "-c", count, host]) if "request timed out" in pingcmd or "unknown host" in pingcmd: diff --git a/plugins/potato.py b/plugins/potato.py index 1fd4b1e..8d03e2b 100755 --- a/plugins/potato.py +++ b/plugins/potato.py @@ -50,5 +50,5 @@ def potato(inp, me=None, input=None): method = random.choice(['bakes', 'fries', 'boils', 'roasts']) side_dish = random.choice(['side salad', 'dollop of sour cream', 'piece of chicken', 'bowl of shredded bacon']) - me("%s a %s %s %s potato for %s and serves it with a small %s!" % ( - method, flavor, size, potato_type, inp, side_dish)) + me("{} a {} {} {} potato for {} and serves it with a small {}!".format(method, flavor, size, potato_type, inp, + side_dish)) diff --git a/plugins/puush.py b/plugins/puush.py index fdf8953..07b1e5c 100644 --- a/plugins/puush.py +++ b/plugins/puush.py @@ -20,7 +20,7 @@ def check_url(code): def make_url(code): - return "http://puu.sh/" + code + return "http://puu.sh/{}".format(code) @hook.command(autohelp=False) diff --git a/plugins/quote.py b/plugins/quote.py index 3d8ad9d..25c614d 100755 --- a/plugins/quote.py +++ b/plugins/quote.py @@ -8,8 +8,8 @@ from util import hook def format_quote(q, num, n_quotes): """Returns a formatted string of a quote""" ctime, nick, msg = q - return "[%d/%d] <%s> %s" % (num, n_quotes, - nick, msg) + return "[{}/{}] <{}> {}".format((num, n_quotes, + nick, msg)) def create_table_if_not_exists(db): @@ -45,12 +45,11 @@ def get_quote_num(num, count, name): if num: # Make sure num is a number if it isn't false num = int(num) if count == 0: # Error on no quotes - raise Exception("No quotes found for %s." % name) + raise Exception("No quotes found for {}.".format(name)) if num and num < 0: # Count back if possible num = count + num + 1 if num + count > -1 else count + 1 if num and num > count: # If there are not enough quotes, raise an error - raise Exception("I only have %d quote%s for %s." - % (count, ('s', '')[count == 1], name)) + raise Exception("I only have {} quote{} for {}.".format(count, ('s', '')[count == 1], name)) if num and num == 0: # If the number is zero, set it to one num = 1 if not num: # If a number is not given, select a random one diff --git a/plugins/reddit.py b/plugins/reddit.py index 609c352..96f96b5 100644 --- a/plugins/reddit.py +++ b/plugins/reddit.py @@ -15,5 +15,5 @@ def reddit_url(match): timeago = thread.xpath("//div[@id='siteTable']//p[@class='tagline']/time/text()")[0] comments = thread.xpath("//div[@id='siteTable']//a[@class='comments']/text()")[0] - return '\x02%s\x02 - posted by \x02%s\x02 %s ago - %s upvotes, %s downvotes - %s' % ( + return '\x02{}\x02 - posted by \x02{}\x02 {} ago - {} upvotes, {} downvotes - {}'.format( title, author, timeago, upvotes, downvotes, comments) diff --git a/plugins/snopes.py b/plugins/snopes.py index bc32f18..9850a68 100755 --- a/plugins/snopes.py +++ b/plugins/snopes.py @@ -31,4 +31,4 @@ def snopes(inp): claim = re.sub(r"[\s\xa0]+", " ", claim) # compress whitespace status = re.sub(r"[\s\xa0]+", " ", status) - return "%s %s %s" % (claim, status, result_urls[0]) + return "{} {} {}".format(claim, status, result_urls[0])