예제 #1
0
파일: core_user.py 프로젝트: ewhal/uguubot
def horoscope(inp, db=None, notice=None, nick=None):
    """horoscope <sign> [save] -- Get your horoscope."""
    save = False
    database.init(db)

    if '@' in inp:
        nick = inp.split('@')[1].strip()
        sign = database.get(db,'users','horoscope','nick',nick)
        if not sign: return "No horoscope sign stored for {}.".format(nick)
    else:
        sign = database.get(db,'users','horoscope','nick',nick)
        if not inp:
            if not sign:
                notice(horoscope.__doc__)
                return
        else:
            if not sign: save = True
            if " save" in inp: save = True
            sign = inp.split()[0]

    import urllib
    url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % sign
    try:
        response = urllib.urlopen(url)
        result = response.read()
        horoscopetxt = result.find('div', {'class': 'block-horoscope-text f16 l20'}).text
    except: return "Could not get the horoscope for {}.".format(sign.encode('utf8'))

    if sign and save: database.set(db,'users','horoscope',sign,'nick',nick)

    return u"\x02{}\x02 {}".format(sign, horoscopetxt)
예제 #2
0
def horoscope(inp, db=None, notice=None, nick=None):
    """horoscope <sign> [save] -- Get your horoscope."""
    save = False
    database.init(db)
    
    if '@' in inp:
        nick = inp.split('@')[1].strip()
        sign = database.get(db,'users','horoscope','nick',nick)
        if not sign: return "No horoscope sign stored for {}.".format(nick)
    else:
        sign = database.get(db,'users','horoscope','nick',nick)
        if not inp: 
            if not sign:
                notice(horoscope.__doc__)
                return
        else:
            if not sign: save = True
            if " save" in inp: save = True
            sign = inp.split()[0]

    url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % sign
    try:
        result = http.get_soup(url)
        title = result.find_all('h1', {'class': 'h1b'})[1].text
        horoscopetxt = result.find('div', {'id': 'textline'}).text
    except: return "Could not get the horoscope for {}.".format(sign.encode('utf8'))

    if sign and save: database.set(db,'users','horoscope',sign,'nick',nick)
    
    return u"\x02{}\x02 {}".format(title, horoscopetxt)
예제 #3
0
def horoscope(inp, db=None, notice=None, nick=None):
    """horoscope <sign> [save] -- Get your horoscope."""
    save = False
    database.init(db)

    if '@' in inp:
        nick = inp.split('@')[1].strip()
        sign = database.get(db, 'users', 'horoscope', 'nick', nick)
        if not sign: return "No horoscope sign stored for {}.".format(nick)
    else:
        sign = database.get(db, 'users', 'horoscope', 'nick', nick)
        if not inp:
            if not sign:
                notice(horoscope.__doc__)
                return
        else:
            if not sign: save = True
            if " save" in inp: save = True
            sign = inp.split()[0]

    url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % sign
    try:
        result = http.get_soup(url)
        title = result.find_all('h1', {'class': 'h1b'})[1].text
        horoscopetxt = result.find('div', {'id': 'textline'}).text
    except:
        return "Could not get the horoscope for {}.".format(
            sign.encode('utf8'))

    if sign and save:
        database.set(db, 'users', 'horoscope', sign, 'nick', nick)

    return u"\x02{}\x02 {}".format(title, horoscopetxt)
예제 #4
0
def horoscope(inp, db=None, notice=None, nick=None):
    """horoscope <sign> [save] -- Get your horoscope."""
    save = False
    database.init(db)

    if '@' in inp:
        nick = inp.split('@')[1].strip()
        sign = database.get(db,'users','horoscope','nick',nick)
        if not sign: return "No horoscope sign stored for {}.".format(nick)
    else:
        sign = database.get(db,'users','horoscope','nick',nick)
        if not inp:
            if not sign:
                notice(horoscope.__doc__)
                return
        else:
            if not sign: save = True
            if " save" in inp: save = True
            sign = inp.split()[0]

    url = "http://www.astrology.com/horoscope/daily/%s.html" % sign
    try:
        request = urllib2.Request(url, None, headers)
        page = urllib2.urlopen(request).read()
        result = BeautifulSoup(page, 'lxml')
        horoscopetxt = http.strip_html(str(result.find('div', attrs={'class':('page-horoscope-text')})))
    except: return "Check your spelling, acronyms and short forms are not accepted."


    if sign and save: database.set(db,'users','horoscope',sign,'nick',nick)
    horoscopetxt = horoscopetxt.rsplit('.', 2)[0]
    horoscopetxt += '.'
    return u"{}".format(horoscopetxt)
예제 #5
0
def db(inp, db=None, notice=None, chan=None):
    """db <update|init> -- Init or update the database."""
    if 'update' in inp:
        database.update(db)
        notice('[{}]: Updated databases.'.format(chan))
    elif 'init' in inp:
        database.init(db)
        notice('[{}]: Initiated databases.'.format(chan))
예제 #6
0
def db(inp, db=None, notice=None, chan=None):
    """db <update|init> -- Init or update the database."""
    print(inp)
    if 'update' in inp:
        database.update(db)
        notice('[{}]: Updated databases.'.format(chan))
    elif 'init' in inp:
        database.init(db)
        notice('[{}]: Initiated databases.'.format(chan))
예제 #7
0
def horoscope(inp, db=None, notice=None, nick=None):
    """horoscope <sign> [save] -- Get your horoscope."""
    save = False
    database.init(db)

    if '@' in inp:
        nick = inp.split('@')[1].strip()
        sign = database.get(db, 'users', 'horoscope', 'nick', nick)
        if not sign:
            return "No horoscope sign stored for {}.".format(nick)
    else:
        sign = database.get(db, 'users', 'horoscope', 'nick', nick)
        if not inp:
            if not sign:
                notice(horoscope.__doc__)
                return
        else:
            if not sign:
                save = True
            if " save" in inp:
                save = True
            sign = inp.split()[0]

    url = "https://my.horoscope.com/astrology/free-daily-horoscope-{}.html".format(
        sign)
    try:
        result = http.get_soup(url)
        container = result.find('div', attrs={'class': 'main-horoscope'})
        if not container:
            return 'Could not parse the horoscope for {}.'.format(sign)

        paragraph = container.find('p')

        if paragraph:
            return nick + ': ' + paragraph.text
        else:
            return 'Could not read the horoscope for {}.'.format(sign)

    except Exception:
        raise
        return "Could not get the horoscope for {}.".format(sign)

    if sign and save:
        database.set(db, 'users', 'horoscope', sign, 'nick', nick)

    return u"\x02{}\x02 {}".format(title, horoscopetxt)
예제 #8
0
def horoscope(inp, db=None, notice=None, nick=None):
    """horoscope <sign> [save] -- Get your horoscope."""
    save = False
    database.init(db)

    if '@' in inp:
        nick = inp.split('@')[1].strip()
        sign = database.get(db, 'users', 'horoscope', 'nick', nick)
        if not sign: return "No horoscope sign stored for {}.".format(nick)
    else:
        sign = database.get(db, 'users', 'horoscope', 'nick', nick)
        if not inp:
            if not sign:
                notice(horoscope.__doc__)
                return
        else:
            if not sign: save = True
            if " save" in inp: save = True
            sign = inp.split()[0]

    import urllib
    url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % sign
    try:
        response = urllib.urlopen(url)
        result = response.read()
        horoscopetxt = result.find('div', {
            'class': 'block-horoscope-text f16 l20'
        }).text
    except:
        return "Could not get the horoscope for {}.".format(
            sign.encode('utf8'))

    if sign and save:
        database.set(db, 'users', 'horoscope', sign, 'nick', nick)

    return u"\x02{}\x02 {}".format(sign, horoscopetxt)
예제 #9
0
from util import database as db

db.init()
# print(db.registerUser("a","a"))
# print(db.registerUser("b","b"))
# print(db.registerUser("c","c"))
# print(db.verifyUser("a","b"))
# print(db.verifyUser("a","a"))

# print(db.saveImage("a","pic1","cap1",False))
# print(db.saveImage("b","pic1","cap1",False))
#
# print(db.getPictures("b"))
# print("_________________________")
# print(db.getImageId("b", "pic1"))

# print(db.createGroup("a","groupa"))
# print(db.createGroup("a","groupa"))

# print(db.requestGroup("b","groupa"))
# print(db.requestGroup("c","groupa"))
#
# print(db.evalRequest("groupa", "a", "b", 1))
# print(db.evalRequest("groupa", "a", "c", 0))
#
# print(db.requestGroup("b","groupa"))
#
# print(db.requestGroup("b","groupa"))
# print(db.evalRequest("groupa", "a", "b", 1))
#
# print(db.getMembers("groupa"))