A few tweaks to plugins: weather.py now uses web.query for YQL, spellcheck.py has some renamed variables and uses new string formatting, choose.py has a nicer fail message.
This commit is contained in:
parent
de67aad764
commit
5f0d5f62a2
3 changed files with 13 additions and 17 deletions
|
@ -13,6 +13,6 @@ def choose(inp):
|
||||||
if len(c) == 1:
|
if len(c) == 1:
|
||||||
c = re.findall(r'(\S+)', inp)
|
c = re.findall(r'(\S+)', inp)
|
||||||
if len(c) == 1:
|
if len(c) == 1:
|
||||||
return 'the decision is up to you'
|
return 'The decision is up to you!'
|
||||||
|
|
||||||
return random.choice(c).strip()
|
return random.choice(c).strip()
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import re
|
|
||||||
import enchant
|
import enchant
|
||||||
from util import hook
|
from util import hook
|
||||||
|
|
||||||
locale = "en_US"
|
locale = "en_US"
|
||||||
|
|
||||||
|
|
||||||
@hook.command("spellcheck")
|
@hook.command
|
||||||
def spell(inp):
|
def spell(inp):
|
||||||
"spell <word> -- Check spelling of <word>."
|
"spell <word> -- Check spelling of <word>."
|
||||||
|
|
||||||
|
@ -13,16 +12,16 @@ def spell(inp):
|
||||||
return "This command only supports one word at a time."
|
return "This command only supports one word at a time."
|
||||||
|
|
||||||
if not enchant.dict_exists(locale):
|
if not enchant.dict_exists(locale):
|
||||||
return "Could not find dictionary: %s" % locale
|
return "Could not find dictionary: {}".format(locale)
|
||||||
|
|
||||||
dict = enchant.Dict(locale)
|
dictionary = enchant.Dict(locale)
|
||||||
is_correct = dict.check(inp)
|
is_correct = dictionary.check(inp)
|
||||||
suggestions = dict.suggest(inp)
|
suggestions = dictionary.suggest(inp)
|
||||||
s_string = ', '.join(suggestions[:10])
|
s_string = ', '.join(suggestions[:10])
|
||||||
|
|
||||||
if is_correct:
|
if is_correct:
|
||||||
return '"%s" appears to be \x02valid\x02! ' \
|
return '"{}" appears to be \x02valid\x02! ' \
|
||||||
'(suggestions: %s)' % (inp, s_string)
|
'(suggestions: {})'.format(inp, s_string)
|
||||||
else:
|
else:
|
||||||
return '"%s" appears to be \x02invalid\x02! ' \
|
return '"{}" appears to be \x02invalid\x02! ' \
|
||||||
'(suggestions: %s)' % (inp, s_string)
|
'(suggestions: {})'.format(inp, s_string)
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
from util import hook
|
from util import hook, web
|
||||||
import yql as YQL
|
|
||||||
|
|
||||||
|
|
||||||
def get_weather(location):
|
def get_weather(location):
|
||||||
"""uses the yahoo weather API to get weather information for a location"""
|
"""uses the yahoo weather API to get weather information for a location"""
|
||||||
|
|
||||||
yql = YQL.Public()
|
|
||||||
enviroment = "http://datatables.org/alltables.env"
|
|
||||||
query = "SELECT * FROM weather.bylocation WHERE location=@location LIMIT 1"
|
query = "SELECT * FROM weather.bylocation WHERE location=@location LIMIT 1"
|
||||||
data = yql.execute(query, {"location": location}, env=enviroment).one()
|
result = web.query(query, {"location": location})
|
||||||
|
|
||||||
data = data["rss"]["channel"]
|
data = result.rows[0]["rss"]["channel"]
|
||||||
|
|
||||||
# wind conversions
|
# wind conversions
|
||||||
data['wind']['chill_c'] = int(round((int(data['wind']['chill']) - 32) / 1.8, 0))
|
data['wind']['chill_c'] = int(round((int(data['wind']['chill']) - 32) / 1.8, 0))
|
||||||
|
|
Reference in a new issue