This commit is contained in:
Luke Rogers 2014-02-14 00:47:01 +13:00
parent ada153c8bc
commit ee0ad67a16
14 changed files with 24 additions and 50 deletions

View File

@ -1,5 +1,5 @@
'''brainfuck interpreter adapted from (public domain) code at
http://brainfuck.sourceforge.net/brain.py'''
"""brainfuck interpreter adapted from (public domain) code at
http://brainfuck.sourceforge.net/brain.py"""
import re
import random

View File

@ -2,7 +2,7 @@ from util import hook, http, web
@hook.command(autohelp=False)
def fact(inp, say=False, nick=False):
def fact(inp):
"""fact -- Gets a random fact from OMGFACTS."""
attempts = 0
@ -20,10 +20,10 @@ def fact(inp, say=False, nick=False):
response = soup.find('a', {'class': 'surprise'})
link = response['href']
fact = ''.join(response.find(text=True))
fact_data = ''.join(response.find(text=True))
if fact:
fact = fact.strip()
if fact_data:
fact_data = fact_data.strip()
break
else:
if attempts > 2:
@ -34,4 +34,4 @@ def fact(inp, say=False, nick=False):
url = web.try_isgd(link)
return "{} - {}".format(fact, url)
return "{} - {}".format(fact_data, url)

View File

@ -3,7 +3,7 @@ from util import hook
@hook.command(autohelp=False)
def help(inp, notice=None, input=None, conn=None, bot=None):
def help(inp, notice=None, conn=None, bot=None):
"""help -- Gives a list of commands/help for a command."""
funcs = {}

View File

@ -10,7 +10,7 @@ def hulu_url(match):
data = http.get_json("http://www.hulu.com/api/oembed.json?url=http://www.hulu.com" + match.group(3))
showname = data['title'].split("(")[-1].split(")")[0]
title = data['title'].split(" (")[0]
return "{}: {} - {}".format(showname, title, timeformat.timeformat(int(data['duration'])))
return "{}: {} - {}".format(showname, title, timeformat.format_time(int(data['duration'])))
@hook.command('hulu')
@ -21,7 +21,7 @@ def hulu_search(inp):
data = result.find('results').find('videos').find('video')
showname = data.find('show').find('name').text
title = data.find('title').text
duration = timeformat.timeformat(int(float(data.find('duration').text)))
duration = timeformat.format_time(int(float(data.find('duration').text)))
description = data.find('description').text
rating = data.find('content-rating').text
return "{}: {} - {} - {} ({}) {}".format(showname, title, description, duration, rating,

View File

@ -18,7 +18,7 @@ def is_valid(data):
@hook.command(autohelp=False)
def imgur(inp):
"imgur [subreddit] -- Gets the first page of imgur images from [subreddit] and returns a link to them. If [subreddit] is undefined, return any imgur images"
"""imgur [subreddit] -- Gets the first page of imgur images from [subreddit] and returns a link to them. If [subreddit] is undefined, return any imgur images"""
if inp:
# see if the input ends with "nsfw"
show_nsfw = inp.endswith(" nsfw")

View File

@ -5,7 +5,7 @@ from util import hook, http, urlnorm
@hook.command
def isup(inp):
"isup -- uses isup.me to see if a site is up or not"
"""isup -- uses isup.me to see if a site is up or not"""
# slightly overcomplicated, esoteric URL parsing
scheme, auth, path, query, fragment = urlparse.urlsplit(inp.strip())

View File

@ -41,36 +41,6 @@ def metacritic(inp):
except HTTPError:
return 'error fetching results'
''' result format:
-- game result, with score
-- subsequent results are the same structure, without first_result class
<li class="result first_result">
<div class="result_type">
<strong>Game</strong>
<span class="platform">WII</span>
</div>
<div class="result_wrap">
<div class="basic_stats has_score">
<div class="main_stats">
<h3 class="product_title basic_stat">...</h3>
<div class="std_score">
<div class="score_wrap">
<span class="label">Metascore: </span>
<span class="data metascore score_favorable">87</span>
</div>
</div>
</div>
<div class="more_stats extended_stats">...</div>
</div>
</div>
</li>
-- other platforms are the same basic layout
-- if it doesn't have a score, there is no div.basic_score
-- the <div class="result_type"> changes content for non-games:
<div class="result_type"><strong>Movie</strong></div>
'''
# get the proper result element we want to pull data from
result = None

View File

@ -23,7 +23,7 @@ refresh_cache()
@hook.command(autohelp=False)
def mlia(inp, reply=None):
"mlia -- Gets a random quote from MyLifeIsAverage.com."
"""mlia -- Gets a random quote from MyLifeIsAverage.com."""
# grab the last item in the mlia cache and remove it
id, text = mlia_cache.pop()
# reply with the mlia we grabbed

View File

@ -44,7 +44,7 @@ def format_item(item, show_url=True):
tags.append("\x02Featured\x02")
if item["IsShellShockerItem"]:
tags.append("\x02SHELL SHOCKER®\x02")
tags.append(u"\x02SHELL SHOCKER\u00AE\x02")
# join all the tags together in a comma separated string ("tag1, tag2, tag3")
tag_text = u", ".join(tags)

View File

@ -4,7 +4,7 @@ import re
db_inited = False
def cleanSQL(sql):
def clean_sql(sql):
return re.sub(r'\s+', " ", sql).strip()
@ -20,7 +20,7 @@ def db_init(db):
""").fetchone()[0] == 1
if not exists:
db.execute(cleanSQL("""
db.execute(clean_sql("""
create virtual table todos using fts4(
user,
text,
@ -91,7 +91,7 @@ def db_search(db, nick, query):
@hook.command("notes")
@hook.command
def note(inp, nick='', chan='', db=None, notice=None, bot=None):
"note(s) <add|del|list|search> args -- Manipulates your list of notes."
"""note(s) <add|del|list|search> args -- Manipulates your list of notes."""
db_init(db)

View File

@ -50,7 +50,7 @@ def tellinput(paraml, input=None, notice=None, db=None, bot=None, nick=None, con
@hook.command(autohelp=False)
def showtells(inp, nick='', chan='', notice=None, db=None):
"showtells -- View all pending tell messages (sent in a notice)."
"""showtells -- View all pending tell messages (sent in a notice)."""
db_init(db)

View File

@ -52,7 +52,7 @@ def twitter_url(match, bot=None):
@hook.command("twatter")
@hook.command
def twitter(inp, bot=None):
"twitter <user> [n] -- Gets last/[n]th tweet from <user>"
"""twitter <user> [n] -- Gets last/[n]th tweet from <user>"""
api = get_api(bot)
if not api:
@ -117,6 +117,9 @@ def twitter(inp, bot=None):
tweet = random.choice(search)
user = tweet.user
else:
# ???
return "Unknown Error"
text = " ".join(tweet.text.split())

View File

@ -89,7 +89,7 @@ def checkbase64(inp):
recoded = decoded.encode('base64').strip()
is_base64 = recoded == inp
except:
is_base64 = False
return '"{}" is not base64 encoded'.format(inp)
if is_base64:
return '"{}" is base64 encoded'.format(recoded)

View File

@ -1,3 +1,4 @@
Crypto
BeautifulSoup==3.2.1
lxml==3.1beta1
pyenchant==1.6.5