PEP-8
This commit is contained in:
parent
e7d69e63c0
commit
549bb70690
5 changed files with 21 additions and 27 deletions
|
@ -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 <word> [+]<data> -- Remembers <data> with <word>. Add + to <data> to append."
|
||||
".remember <word> [+]<data> -- Remembers <data> with <word>. Add +"
|
||||
" to <data> 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!')
|
||||
|
|
|
@ -5,7 +5,8 @@ import urllib2
|
|||
|
||||
@hook.command
|
||||
def gitio(inp):
|
||||
".gitio <url> [code] -- Shorten Github URLs with git.io. [code] is a optional custom short code."
|
||||
".gitio <url> [code] -- Shorten Github URLs with git.io. [code] is"
|
||||
" a optional custom short code."
|
||||
split = inp.split(" ")
|
||||
url = split[0]
|
||||
|
||||
|
|
|
@ -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,6 +30,7 @@ def bitly(url, user, apikey):
|
|||
except (HTTPError, ShortenError):
|
||||
return "Could not shorten %s!" % url
|
||||
|
||||
|
||||
@hook.command
|
||||
def shorten(inp, bot=None):
|
||||
".shorten <url> - Makes an j.mp/bit.ly shortlink to the url provided."
|
||||
|
@ -35,12 +39,3 @@ def shorten(inp, bot = 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 <url> - Gets the original URL from a shortened link."
|
||||
try:
|
||||
url = http.get_url(inp)
|
||||
except HTTPError, e:
|
||||
return "Failed to expand URL."
|
||||
return url
|
||||
|
|
|
@ -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 <word> -- Makes a slogan for <word>."
|
||||
|
|
|
@ -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
|
||||
|
@ -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)
|
||||
|
|
Reference in a new issue