PEP8
This commit is contained in:
parent
ba565a3eaa
commit
c2a607198c
|
@ -18,7 +18,7 @@ split_re = re.compile(r'([\d+-]*)d?(F|\d*)', re.I)
|
||||||
def nrolls(count, n):
|
def nrolls(count, n):
|
||||||
"roll an n-sided die count times"
|
"roll an n-sided die count times"
|
||||||
if n == "F":
|
if n == "F":
|
||||||
return [random.randint(-1,1) for x in xrange(count)]
|
return [random.randint(-1, 1) for x in xrange(min(count, 100))]
|
||||||
if n < 2: # it's a coin
|
if n < 2: # it's a coin
|
||||||
if count < 5000:
|
if count < 5000:
|
||||||
return [random.randint(0, 1) for x in xrange(count)]
|
return [random.randint(0, 1) for x in xrange(count)]
|
||||||
|
@ -38,13 +38,15 @@ def nrolls(count, n):
|
||||||
def dice(inp):
|
def dice(inp):
|
||||||
".dice <diceroll> -- simulates dicerolls, e.g. .dice 2d20-d5+4 roll 2 " \
|
".dice <diceroll> -- simulates dicerolls, e.g. .dice 2d20-d5+4 roll 2 " \
|
||||||
"D20s, subtract 1D5, add 4"
|
"D20s, subtract 1D5, add 4"
|
||||||
desc = None
|
|
||||||
try: # if inp is a re.match object...
|
try: # if inp is a re.match object...
|
||||||
(inp, desc) = inp.groups()
|
(inp, desc) = inp.groups()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass # we got called via hook.command, inp is already the roll
|
(inp, desc) = valid_diceroll_re.match(inp).groups()
|
||||||
if desc == None: (inp, desc) = valid_diceroll_re.match(inp).groups()
|
|
||||||
if "d" not in inp: return
|
if "d" not in inp:
|
||||||
|
return
|
||||||
|
|
||||||
spec = whitespace_re.sub('', inp)
|
spec = whitespace_re.sub('', inp)
|
||||||
if not valid_diceroll_re.match(spec):
|
if not valid_diceroll_re.match(spec):
|
||||||
return "Invalid diceroll"
|
return "Invalid diceroll"
|
||||||
|
|
|
@ -37,7 +37,6 @@ def google(inp):
|
||||||
|
|
||||||
result = parsed['responseData']['results'][0]
|
result = parsed['responseData']['results'][0]
|
||||||
|
|
||||||
|
|
||||||
title = result['titleNoFormatting']
|
title = result['titleNoFormatting']
|
||||||
content = result['content']
|
content = result['content']
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ from util import hook, http
|
||||||
thread_re = r"(?i)forums\.somethingawful\.com/\S+threadid=(\d+)"
|
thread_re = r"(?i)forums\.somethingawful\.com/\S+threadid=(\d+)"
|
||||||
showthread = "http://forums.somethingawful.com/showthread.php?noseen=1"
|
showthread = "http://forums.somethingawful.com/showthread.php?noseen=1"
|
||||||
|
|
||||||
|
|
||||||
def login(user, password):
|
def login(user, password):
|
||||||
http.jar.clear_expired_cookies()
|
http.jar.clear_expired_cookies()
|
||||||
if any(cookie.domain == 'forums.somethingawful.com' and
|
if any(cookie.domain == 'forums.somethingawful.com' and
|
||||||
|
|
|
@ -62,4 +62,5 @@ def tv_next(inp):
|
||||||
if len(next_eps) == 1:
|
if len(next_eps) == 1:
|
||||||
return "the next episode of %s airs %s" % (series_name, next_eps[0])
|
return "the next episode of %s airs %s" % (series_name, next_eps[0])
|
||||||
else:
|
else:
|
||||||
return "the next episodes of %s: %s" % (series_name, ", ".join(next_eps))
|
next_eps = ', '.join(next_eps)
|
||||||
|
return "the next episodes of %s: %s" % (series_name, next_eps)
|
||||||
|
|
|
@ -122,7 +122,7 @@ def twitter(inp):
|
||||||
reply_user = tweet.find(reply_user).text
|
reply_user = tweet.find(reply_user).text
|
||||||
if reply_name is not None and (reply_id is not None or
|
if reply_name is not None and (reply_id is not None or
|
||||||
reply_user is not None):
|
reply_user is not None):
|
||||||
add_reply(reply_name, reply_id if reply_id else -1)
|
add_reply(reply_name, reply_id or -1)
|
||||||
|
|
||||||
time = strftime('%Y-%m-%d %H:%M:%S',
|
time = strftime('%Y-%m-%d %H:%M:%S',
|
||||||
strptime(time.text,
|
strptime(time.text,
|
||||||
|
|
|
@ -23,13 +23,16 @@ inspired by:
|
||||||
|
|
||||||
__license__ = "Python"
|
__license__ = "Python"
|
||||||
|
|
||||||
import re, unicodedata, urlparse
|
import re
|
||||||
|
import unicodedata
|
||||||
|
import urlparse
|
||||||
from urllib import quote, unquote
|
from urllib import quote, unquote
|
||||||
|
|
||||||
default_port = {
|
default_port = {
|
||||||
'http': 80,
|
'http': 80,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Normalizer(object):
|
class Normalizer(object):
|
||||||
def __init__(self, regex, normalize_func):
|
def __init__(self, regex, normalize_func):
|
||||||
self.regex = regex
|
self.regex = regex
|
||||||
|
@ -43,6 +46,7 @@ normalizers = ( Normalizer( re.compile(r'(?:https?://)?(?:[a-zA-Z0-9\-]+\.)?(?:a
|
||||||
lambda m: r'http://youtube.com/watch?v=%s' % m.group(1) ),
|
lambda m: r'http://youtube.com/watch?v=%s' % m.group(1) ),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def normalize(url):
|
def normalize(url):
|
||||||
"""Normalize a URL."""
|
"""Normalize a URL."""
|
||||||
|
|
||||||
|
@ -54,12 +58,15 @@ def normalize(url):
|
||||||
|
|
||||||
# Always provide the host, if any, in lowercase characters.
|
# Always provide the host, if any, in lowercase characters.
|
||||||
host = host.lower()
|
host = host.lower()
|
||||||
if host and host[-1] == '.': host = host[:-1]
|
if host and host[-1] == '.':
|
||||||
|
host = host[:-1]
|
||||||
if host and host.startswith("www."):
|
if host and host.startswith("www."):
|
||||||
if not scheme: scheme = "http"
|
if not scheme:
|
||||||
|
scheme = "http"
|
||||||
host = host[4:]
|
host = host[4:]
|
||||||
elif path and path.startswith("www."):
|
elif path and path.startswith("www."):
|
||||||
if not scheme: scheme = "http"
|
if not scheme:
|
||||||
|
scheme = "http"
|
||||||
path = path[4:]
|
path = path[4:]
|
||||||
|
|
||||||
# Only perform percent-encoding where it is essential.
|
# Only perform percent-encoding where it is essential.
|
||||||
|
@ -80,19 +87,23 @@ def normalize(url):
|
||||||
output = []
|
output = []
|
||||||
for input in path.split('/'):
|
for input in path.split('/'):
|
||||||
if input == "":
|
if input == "":
|
||||||
if not output: output.append(input)
|
if not output:
|
||||||
|
output.append(input)
|
||||||
elif input == ".":
|
elif input == ".":
|
||||||
pass
|
pass
|
||||||
elif input == "..":
|
elif input == "..":
|
||||||
if len(output)>1: output.pop()
|
if len(output) > 1:
|
||||||
|
output.pop()
|
||||||
else:
|
else:
|
||||||
output.append(input)
|
output.append(input)
|
||||||
if input in ["", ".", ".."]: output.append("")
|
if input in ["", ".", ".."]:
|
||||||
|
output.append("")
|
||||||
path = '/'.join(output)
|
path = '/'.join(output)
|
||||||
|
|
||||||
# For schemes that define a default authority, use an empty authority if
|
# For schemes that define a default authority, use an empty authority if
|
||||||
# the default is desired.
|
# the default is desired.
|
||||||
if userinfo in ["@", ":@"]: userinfo=""
|
if userinfo in ["@", ":@"]:
|
||||||
|
userinfo = ""
|
||||||
|
|
||||||
# For schemes that define an empty path to be equivalent to a path of "/",
|
# For schemes that define an empty path to be equivalent to a path of "/",
|
||||||
# use "/".
|
# use "/".
|
||||||
|
@ -113,8 +124,8 @@ def normalize(url):
|
||||||
auth += ":" + port
|
auth += ":" + port
|
||||||
if url.endswith("#") and query == "" and fragment == "":
|
if url.endswith("#") and query == "" and fragment == "":
|
||||||
path += "#"
|
path += "#"
|
||||||
normal_url = urlparse.urlunsplit((scheme, auth, path, query, fragment)).replace(
|
normal_url = urlparse.urlunsplit((scheme, auth, path, query,
|
||||||
"http:///", "http://")
|
fragment)).replace("http:///", "http://")
|
||||||
for norm in normalizers:
|
for norm in normalizers:
|
||||||
m = norm.regex.match(normal_url)
|
m = norm.regex.match(normal_url)
|
||||||
if m:
|
if m:
|
||||||
|
|
Loading…
Reference in New Issue