This commit is contained in:
Luke Rogers 2014-03-06 14:02:26 +13:00
parent 141fe8d80c
commit f81cf21b57
10 changed files with 18 additions and 18 deletions

View File

@ -7,8 +7,8 @@ import time
import signal
# check python version
if sys.version_info < (2, 7, 0):
print("CloudBot requires Python 2.7 or newer.")
if sys.version_info < (3, 2, 0):
print("CloudBot3 requires Python 3.2 or newer.")
sys.exit(1)
# set up enviroment
@ -18,10 +18,10 @@ os.chdir(sys.path[0] or '.') # do stuff relative to the install directory
if os.path.exists(os.path.abspath('lib')):
sys.path += ['lib']
print('CloudBot2 <http://git.io/cloudbotirc>')
print('CloudBot3 <http://git.io/cloudbotirc>')
def exit_gracefully(signum, frame):
# this doesn't really work that well
# this doesn't really work at all
cloudbot.stop()
# restore the original handler so if they do it again it triggers
@ -42,6 +42,7 @@ while True:
else:
if cloudbot.do_restart:
# create a new bot thread and start it
# THIS DOES NOT WORK
del cloudbot
cloudbot = bot.Bot()
cloudbot.start()

View File

@ -37,7 +37,7 @@ def ghissues(inp):
except IndexError:
return "Invalid syntax. .github issues username/repo [number]"
try:
url += "/%s" % args[1]
url += "/{}".format(args[1])
number = True
except IndexError:
number = False

View File

@ -41,8 +41,8 @@ def help_command(inp, notice=None, conn=None, bot=None):
if len(out) > 1:
for x in out[1:]:
notice(x)
notice("For detailed help, do '%shelp <example>' where <example> "
"is the name of the command you want help for." % conn.conf["command_prefix"])
notice("For detailed help, do '{}help <example>' where <example> "
"is the name of the command you want help for.".format(conn.conf["command_prefix"]))
else:
if inp in commands:

View File

@ -46,7 +46,7 @@ def horoscope(inp, db=None, notice=None, nick=None):
title = soup.find_all('h1', {'class': 'h1b'})[1]
horoscope_text = soup.find('div', {'class': 'fontdef1'})
result = "\x02%s\x02 %s" % (title, horoscope_text)
result = "\x02{}\x02 {}".format(title, horoscope_text)
result = text.strip_html(result)
#result = unicode(result, "utf8").replace('flight ','')

View File

@ -25,8 +25,8 @@ def snopes(inp):
if status is not None:
status = status.group(0).strip()
else: # new-style statuses
status = "Status: %s." % re.search(r"FALSE|TRUE|MIXTURE|UNDETERMINED",
snopes_text).group(0).title()
status = "Status: {}.".format(re.search(r"FALSE|TRUE|MIXTURE|UNDETERMINED",
snopes_text).group(0).title())
claim = re.sub(r"[\s\xa0]+", " ", claim) # compress whitespace
status = re.sub(r"[\s\xa0]+", " ", status)

View File

@ -24,8 +24,8 @@ def sptfy(inp, sptfy=False):
link = soup.find('div', {'class': 'resultLink'}).text.strip()
return link
except:
message = "Unable to shorten URL: %s" % \
soup.find('div', {'class': 'messagebox_text'}).find('p').text.split("<br/>")[0]
message = "Unable to shorten URL: {}".format(soup.find('div', {
'class': 'messagebox_text'}).find('p').text.split("<br/>")[0])
return message
else:
return web.try_isgd(inp)

View File

@ -41,7 +41,6 @@ def urban(inp):
url = definitions[id_num - 1]['permalink']
output = "[%i/%i] %s :: %s" % \
(id_num, len(definitions), definition, url)
output = "[{}/{}] {} :: {}".format(id_num, len(definitions), definition, url)
return output

View File

@ -11,10 +11,10 @@ months = {1: 'January', 2: 'February', 3: 'March', 4: 'April', 5: 'May', 6: 'Jun
def xkcd_info(xkcd_id, url=False):
""" takes an XKCD entry ID and returns a formatted string """
data = http.get_json("http://www.xkcd.com/" + xkcd_id + "/info.0.json")
date = "%s %s %s" % (data['day'], months[int(data['month'])], data['year'])
date = "{} {} {}".format(data['day'], months[int(data['month'])], data['year'])
if url:
url = " | http://xkcd.com/" + xkcd_id.replace("/", "")
return "xkcd: \x02%s\x02 (%s)%s" % (data['title'], date, url if url else "")
return "xkcd: \x02{}\x02 ({}){}".format(data['title'], date, url if url else "")
def xkcd_search(term):

View File

@ -134,4 +134,4 @@ def ytplaylist_url(match):
author = soup.find('img', {'class': 'channel-header-profile-image'})['title']
num_videos = soup.find('ul', {'class': 'header-stats'}).findAll('li')[0].text.split(' ')[0]
views = soup.find('ul', {'class': 'header-stats'}).findAll('li')[1].text.split(' ')[0]
return "\x02%s\x02 - \x02%s\x02 views - \x02%s\x02 videos - \x02%s\x02" % (title, views, num_videos, author)
return "\x02{}\x02 - \x02{}\x02 views - \x02{}\x02 videos - \x0{}\x02".format(title, views, num_videos, author)

View File

@ -23,7 +23,7 @@ def isgd(url):
""" shortens a URL with the is.gd API """
url = urlnorm.normalize(url.encode('utf-8'), assume_scheme='http')
params = urllib.parse.urlencode({'format': 'json', 'url': url})
request = http.get_json("http://is.gd/create.php?%s" % params)
request = http.get_json("http://is.gd/create.php?{}".format(params))
if "errorcode" in request:
raise ShortenError(request["errorcode"], request["errormessage"])