tidying!
This commit is contained in:
parent
ada153c8bc
commit
ee0ad67a16
14 changed files with 24 additions and 50 deletions
|
@ -1,5 +1,5 @@
|
||||||
'''brainfuck interpreter adapted from (public domain) code at
|
"""brainfuck interpreter adapted from (public domain) code at
|
||||||
http://brainfuck.sourceforge.net/brain.py'''
|
http://brainfuck.sourceforge.net/brain.py"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import random
|
import random
|
||||||
|
|
|
@ -2,7 +2,7 @@ from util import hook, http, web
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def fact(inp, say=False, nick=False):
|
def fact(inp):
|
||||||
"""fact -- Gets a random fact from OMGFACTS."""
|
"""fact -- Gets a random fact from OMGFACTS."""
|
||||||
|
|
||||||
attempts = 0
|
attempts = 0
|
||||||
|
@ -20,10 +20,10 @@ def fact(inp, say=False, nick=False):
|
||||||
|
|
||||||
response = soup.find('a', {'class': 'surprise'})
|
response = soup.find('a', {'class': 'surprise'})
|
||||||
link = response['href']
|
link = response['href']
|
||||||
fact = ''.join(response.find(text=True))
|
fact_data = ''.join(response.find(text=True))
|
||||||
|
|
||||||
if fact:
|
if fact_data:
|
||||||
fact = fact.strip()
|
fact_data = fact_data.strip()
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if attempts > 2:
|
if attempts > 2:
|
||||||
|
@ -34,4 +34,4 @@ def fact(inp, say=False, nick=False):
|
||||||
|
|
||||||
url = web.try_isgd(link)
|
url = web.try_isgd(link)
|
||||||
|
|
||||||
return "{} - {}".format(fact, url)
|
return "{} - {}".format(fact_data, url)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from util import hook
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@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."""
|
"""help -- Gives a list of commands/help for a command."""
|
||||||
|
|
||||||
funcs = {}
|
funcs = {}
|
||||||
|
|
|
@ -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))
|
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]
|
showname = data['title'].split("(")[-1].split(")")[0]
|
||||||
title = data['title'].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')
|
@hook.command('hulu')
|
||||||
|
@ -21,7 +21,7 @@ def hulu_search(inp):
|
||||||
data = result.find('results').find('videos').find('video')
|
data = result.find('results').find('videos').find('video')
|
||||||
showname = data.find('show').find('name').text
|
showname = data.find('show').find('name').text
|
||||||
title = data.find('title').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
|
description = data.find('description').text
|
||||||
rating = data.find('content-rating').text
|
rating = data.find('content-rating').text
|
||||||
return "{}: {} - {} - {} ({}) {}".format(showname, title, description, duration, rating,
|
return "{}: {} - {} - {} ({}) {}".format(showname, title, description, duration, rating,
|
||||||
|
|
|
@ -18,7 +18,7 @@ def is_valid(data):
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def imgur(inp):
|
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:
|
if inp:
|
||||||
# see if the input ends with "nsfw"
|
# see if the input ends with "nsfw"
|
||||||
show_nsfw = inp.endswith(" nsfw")
|
show_nsfw = inp.endswith(" nsfw")
|
||||||
|
|
|
@ -5,7 +5,7 @@ from util import hook, http, urlnorm
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
def isup(inp):
|
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
|
# slightly overcomplicated, esoteric URL parsing
|
||||||
scheme, auth, path, query, fragment = urlparse.urlsplit(inp.strip())
|
scheme, auth, path, query, fragment = urlparse.urlsplit(inp.strip())
|
||||||
|
|
|
@ -41,36 +41,6 @@ def metacritic(inp):
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
return 'error fetching results'
|
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
|
# get the proper result element we want to pull data from
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ refresh_cache()
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def mlia(inp, reply=None):
|
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
|
# grab the last item in the mlia cache and remove it
|
||||||
id, text = mlia_cache.pop()
|
id, text = mlia_cache.pop()
|
||||||
# reply with the mlia we grabbed
|
# reply with the mlia we grabbed
|
||||||
|
|
|
@ -44,7 +44,7 @@ def format_item(item, show_url=True):
|
||||||
tags.append("\x02Featured\x02")
|
tags.append("\x02Featured\x02")
|
||||||
|
|
||||||
if item["IsShellShockerItem"]:
|
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")
|
# join all the tags together in a comma separated string ("tag1, tag2, tag3")
|
||||||
tag_text = u", ".join(tags)
|
tag_text = u", ".join(tags)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import re
|
||||||
db_inited = False
|
db_inited = False
|
||||||
|
|
||||||
|
|
||||||
def cleanSQL(sql):
|
def clean_sql(sql):
|
||||||
return re.sub(r'\s+', " ", sql).strip()
|
return re.sub(r'\s+', " ", sql).strip()
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ def db_init(db):
|
||||||
""").fetchone()[0] == 1
|
""").fetchone()[0] == 1
|
||||||
|
|
||||||
if not exists:
|
if not exists:
|
||||||
db.execute(cleanSQL("""
|
db.execute(clean_sql("""
|
||||||
create virtual table todos using fts4(
|
create virtual table todos using fts4(
|
||||||
user,
|
user,
|
||||||
text,
|
text,
|
||||||
|
@ -91,7 +91,7 @@ def db_search(db, nick, query):
|
||||||
@hook.command("notes")
|
@hook.command("notes")
|
||||||
@hook.command
|
@hook.command
|
||||||
def note(inp, nick='', chan='', db=None, notice=None, bot=None):
|
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)
|
db_init(db)
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ def tellinput(paraml, input=None, notice=None, db=None, bot=None, nick=None, con
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def showtells(inp, nick='', chan='', notice=None, db=None):
|
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)
|
db_init(db)
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ def twitter_url(match, bot=None):
|
||||||
@hook.command("twatter")
|
@hook.command("twatter")
|
||||||
@hook.command
|
@hook.command
|
||||||
def twitter(inp, bot=None):
|
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)
|
api = get_api(bot)
|
||||||
if not api:
|
if not api:
|
||||||
|
@ -117,6 +117,9 @@ def twitter(inp, bot=None):
|
||||||
|
|
||||||
tweet = random.choice(search)
|
tweet = random.choice(search)
|
||||||
user = tweet.user
|
user = tweet.user
|
||||||
|
else:
|
||||||
|
# ???
|
||||||
|
return "Unknown Error"
|
||||||
|
|
||||||
text = " ".join(tweet.text.split())
|
text = " ".join(tweet.text.split())
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ def checkbase64(inp):
|
||||||
recoded = decoded.encode('base64').strip()
|
recoded = decoded.encode('base64').strip()
|
||||||
is_base64 = recoded == inp
|
is_base64 = recoded == inp
|
||||||
except:
|
except:
|
||||||
is_base64 = False
|
return '"{}" is not base64 encoded'.format(inp)
|
||||||
|
|
||||||
if is_base64:
|
if is_base64:
|
||||||
return '"{}" is base64 encoded'.format(recoded)
|
return '"{}" is base64 encoded'.format(recoded)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
Crypto
|
||||||
BeautifulSoup==3.2.1
|
BeautifulSoup==3.2.1
|
||||||
lxml==3.1beta1
|
lxml==3.1beta1
|
||||||
pyenchant==1.6.5
|
pyenchant==1.6.5
|
||||||
|
|
Reference in a new issue