more .format.
This commit is contained in:
parent
7ab4f756fe
commit
0aa2185ede
15 changed files with 41 additions and 49 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(" ", "+")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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])
|
||||
|
|
Reference in a new issue