Added memory to horoscope, removed debug text (closes #101)
This commit is contained in:
parent
132ad104ed
commit
1d74e455a2
2 changed files with 38 additions and 4 deletions
|
@ -61,7 +61,6 @@ def sieve_suite(bot, input, func, kind, args):
|
|||
group_users = bot.config.get("permissions", {}).get(group, [])["users"]
|
||||
group_users = [_mask.lower() for _mask in group_users]
|
||||
for pattern in group_users:
|
||||
print mask + pattern
|
||||
if fnmatch(mask, pattern):
|
||||
return input
|
||||
|
||||
|
|
|
@ -2,11 +2,41 @@
|
|||
|
||||
from util import hook, http
|
||||
|
||||
@hook.command
|
||||
def horoscope(inp):
|
||||
db_ready = False
|
||||
|
||||
|
||||
def db_init(db):
|
||||
"check to see that our db has the horoscope table and return a connection."
|
||||
db.execute("create table if not exists horoscope(nick primary key, sign)")
|
||||
db.commit()
|
||||
db_ready = True
|
||||
|
||||
|
||||
@hook.command(autohelp=False)
|
||||
def horoscope(inp, db=None, notice=None, nick=None):
|
||||
"horoscope <sign> -- Get your horoscope."
|
||||
|
||||
url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % inp
|
||||
if not db_ready:
|
||||
db_init(db)
|
||||
|
||||
# check if the user asked us not to save his details
|
||||
dontsave = inp.endswith(" dontsave")
|
||||
if dontsave:
|
||||
sign = inp[:-9].strip().lower()
|
||||
else:
|
||||
sign = inp
|
||||
|
||||
db.execute("create table if not exists horoscope(nick primary key, sign)")
|
||||
|
||||
if not sign:
|
||||
sign = db.execute("select sign from horoscope where nick=lower(?)",
|
||||
(nick,)).fetchone()
|
||||
if not sign:
|
||||
notice(horoscope.__doc__)
|
||||
return
|
||||
sign = sign[0]
|
||||
|
||||
url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % sign
|
||||
soup = http.get_soup(url)
|
||||
|
||||
title = soup.find_all('h1', {'class': 'h1b'})[1]
|
||||
|
@ -18,4 +48,9 @@ def horoscope(inp):
|
|||
if not title:
|
||||
return "Could not get the horoscope for %s." % inp
|
||||
|
||||
if inp and not dontsave:
|
||||
db.execute("insert or replace into horoscope(nick, sign) values (?,?)",
|
||||
(nick.lower(), sign))
|
||||
db.commit()
|
||||
|
||||
return result
|
Reference in a new issue