Skip to content

Commit 04f823e

Browse files
authored
Merge pull request CloudBotIRC#129 from linuxdaemon/gonzobot+horoscope-fix
Cleanup of horoscope.py
2 parents 91c4dab + 7fffb48 commit 04f823e

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

plugins/horoscope.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616

1717

1818
@hook.command(autohelp=False)
19-
def horoscope(text, db, bot, notice, nick, reply):
20-
"""<sign> - get your horoscope"""
19+
def horoscope(text, db, bot, nick, notice, notice_doc, reply, message):
20+
"""[sign] - get your horoscope"""
2121
signs = {
22-
'aries': '1',
23-
'taurus': '2',
24-
'gemini': '3',
25-
'cancer': '4',
26-
'leo': '5',
27-
'virgo': '6',
28-
'libra': '7',
29-
'scorpio': '8',
30-
'sagittarius': '9',
31-
'capricorn': '10',
32-
'aquarius': '11',
33-
'pisces': '12'
22+
'aries': '1',
23+
'taurus': '2',
24+
'gemini': '3',
25+
'cancer': '4',
26+
'leo': '5',
27+
'virgo': '6',
28+
'libra': '7',
29+
'scorpio': '8',
30+
'sagittarius': '9',
31+
'capricorn': '10',
32+
'aquarius': '11',
33+
'pisces': '12'
3434
}
3535

3636
headers = {'User-Agent': bot.user_agent}
@@ -43,15 +43,19 @@ def horoscope(text, db, bot, notice, nick, reply):
4343
sign = text.strip().lower()
4444

4545
if not sign:
46-
sign = db.execute("select sign from horoscope where "
46+
sign = db.execute("SELECT sign FROM horoscope WHERE "
4747
"nick=lower(:nick)", {'nick': nick}).fetchone()
4848
if not sign:
49-
notice("horoscope <sign> -- Get your horoscope")
49+
notice_doc()
5050
return
5151
sign = sign[0].strip().lower()
5252

53+
if sign not in signs:
54+
notice("Unknown sign: {}".format(sign))
55+
return
56+
5357
params = {
54-
"sign": signs[sign]
58+
"sign": signs[sign]
5559
}
5660

5761
url = "http://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-today.aspx"
@@ -66,17 +70,11 @@ def horoscope(text, db, bot, notice, nick, reply):
6670
soup = BeautifulSoup(request.text)
6771

6872
horoscope_text = soup.find("div", class_="horoscope-content").find("p").text
69-
'''
70-
if not horoscope_text:
71-
return "Could not get the horoscope for {}. Hororscope text error".format(sign)
72-
else:
73-
horoscope_text = horoscope_text[0].text.strip()
74-
'''
7573
result = "\x02{}\x02 {}".format(text, horoscope_text)
7674

7775
if text and not dontsave:
7876
db.execute("insert or replace into horoscope(nick, sign) values (:nick, :sign)",
7977
{'nick': nick.lower(), 'sign': sign})
8078
db.commit()
8179

82-
return result
80+
message(result)

0 commit comments

Comments
 (0)