From 549bb70690e4f89cc9e3ff1c808255cf64c0f456 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 23 Mar 2012 13:32:48 +1300 Subject: [PATCH] PEP-8 --- plugins/factoids.py | 10 ++++++---- plugins/gitio.py | 3 ++- plugins/shorten.py | 19 +++++++------------ plugins/slogan.py | 2 ++ plugins/twitter.py | 14 ++++---------- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/plugins/factoids.py b/plugins/factoids.py index 74b3e1f..106aa14 100755 --- a/plugins/factoids.py +++ b/plugins/factoids.py @@ -24,7 +24,8 @@ def db_init(db): def get_memory(db, word): - row = db.execute("select data from mem where word=lower(?)", [word]).fetchone() + row = db.execute("select data from mem where word=lower(?)", + [word]).fetchone() if row: return row[0] else: @@ -46,7 +47,8 @@ def multiwordReplace(text, wordDic): @hook.command("r", adminonly=True) @hook.command(adminonly=True) def remember(inp, nick='', db=None, say=None, input=None, notice=None): - ".remember [+] -- Remembers with . Add + to to append." + ".remember [+] -- Remembers with . Add +" + " to to append." db_init(db) append = False @@ -78,8 +80,8 @@ def remember(inp, nick='', db=None, say=None, input=None, notice=None): if append: notice("Appending %s to %s" % (new, data.replace('"', "''"))) else: - notice('Forgetting existing data (%s), remembering this instead!' % \ - data.replace('"', "''")) + notice('Forgetting existing data (%s), remembering this instead!' + % data.replace('"', "''")) return else: notice('Remembered!') diff --git a/plugins/gitio.py b/plugins/gitio.py index 287eed0..3aa825d 100755 --- a/plugins/gitio.py +++ b/plugins/gitio.py @@ -5,7 +5,8 @@ import urllib2 @hook.command def gitio(inp): - ".gitio [code] -- Shorten Github URLs with git.io. [code] is a optional custom short code." + ".gitio [code] -- Shorten Github URLs with git.io. [code] is" + " a optional custom short code." split = inp.split(" ") url = split[0] diff --git a/plugins/shorten.py b/plugins/shorten.py index 8a028a4..7e7daf2 100755 --- a/plugins/shorten.py +++ b/plugins/shorten.py @@ -1,4 +1,4 @@ -# Plugin by Lukeroge +# Plugin by Lukeroge # from util import hook, http @@ -6,6 +6,7 @@ from re import match from urllib2 import urlopen, Request, HTTPError from urllib import urlencode + class ShortenError(Exception): def __init__(self, value): self.value = value @@ -13,13 +14,15 @@ class ShortenError(Exception): def __str__(self): return repr(self.value) + def bitly(url, user, apikey): try: if url[:8] == "https://": pass elif url[:7] != "http://": url = "http://" + url - params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, 'format': 'json'}) + params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, + 'format': 'json'}) j = http.get_json("http://api.bit.ly/v3/shorten?%s" % params) if j['status_code'] == 200: return j['data']['url'] @@ -27,20 +30,12 @@ def bitly(url, user, apikey): except (HTTPError, ShortenError): return "Could not shorten %s!" % url + @hook.command -def shorten(inp, bot = None): +def shorten(inp, bot=None): ".shorten - Makes an j.mp/bit.ly shortlink to the url provided." api_user = bot.config.get("api_keys", {}).get("bitly_user", None) api_key = bot.config.get("api_keys", {}).get("bitly_api", None) if api_key is None: return "error: no api key set" return bitly(inp, api_user, api_key) - -@hook.command -def expand(inp, bot = None): - ".expand - Gets the original URL from a shortened link." - try: - url = http.get_url(inp) - except HTTPError, e: - return "Failed to expand URL." - return url diff --git a/plugins/slogan.py b/plugins/slogan.py index bc31db6..711fe6c 100755 --- a/plugins/slogan.py +++ b/plugins/slogan.py @@ -2,10 +2,12 @@ from util import hook, http, misc import re import string + def sloganize(word): bytes = http.get('http://www.sloganizer.net/en/outbound.php', slogan=word) return bytes + @hook.command("slogan") def sloganizr(inp, nick=None, say=None, input=None): ".slogan -- Makes a slogan for ." diff --git a/plugins/twitter.py b/plugins/twitter.py index 7acaa19..9b78fef 100755 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -12,19 +12,13 @@ from util import hook, http, timesince def unescape_xml(string): - # unescape the 5 chars that might be escaped in xml - - # gratuitously functional - # return reduce(lambda x, y: x.replace(*y), (string, - # zip('> < ' "e; &'.split(), '> < \' " &'.split())) - - # boring, normal return string.replace('>', '>').replace('<', '<').replace(''', "'").replace('"e;', '"').replace('&', '&') history = [] history_max_size = 250 + def parseDateTime(s): if s is None: return None @@ -40,7 +34,7 @@ def parseDateTime(s): tzname = 'UTC' tz = FixedOffset(timedelta(hours=tzhour, minutes=tzmin), tzname) - + x = datetime.strptime(datestr, "%Y-%m-%d %H:%M:%S") if fractional is None: fractional = '0' @@ -154,9 +148,9 @@ def twitter(inp): strptime(time.text, '%a %b %d %H:%M:%S +0000 %Y')) - time_pretty = timesince.timesince(parseDateTime(time_raw), datetime.utcnow()) + time_nice = timesince.timesince(parseDateTime(time_raw), datetime.utcnow()) text = unescape_xml(tweet.find(text).text.replace('\n', '')) screen_name = tweet.find(screen_name).text - return "\x02@%s\x02: %s (%s ago)" % (screen_name, text, time_pretty) + return "\x02@%s\x02: %s (%s ago)" % (screen_name, text, time_nice)