Example #1
0
 def getwhodown(self, item):
     """ get list of who downed a karma item """
     item = item.lower()
     s = create_session()
     karma = s.query(WhoKarma).filter(WhoKarma.item==item).filter(WhoKarma.updown=='down')
     if karma:
         return [k.nick for k in karma]
Example #2
0
 def search(self, item):
     """ search for matching karma item """
     item = item.lower()
     s = create_session()
     karma = s.query(Karma).filter(Karma.item.like('%%%s%%' % item))
     if karma:
         return karma
Example #3
0
 def whykarmadown(self, item):
     """ get why of karma downs """
     s = create_session()
     item = item.lower()
     karma = s.query(WhyKarma).filter(WhyKarma.item==item).filter(WhyKarma.updown=='down')
     if karma:
         return [k.why for k in karma]
Example #4
0
 def searchlast(self, what, nr):
     """ search quotes """
     s = create_session()
     result = s.query(Quotes).filter(Quotes.quote.like(
         '%%%s%%' % what)).order_by(Quotes.indx.desc()).limit(nr)
     if result:
         return result
Example #5
0
 def get(self, item):
     """ get karma of item """
     item = item.lower()
     s = create_session()
     karma = s.query(Karma).filter(Karma.item==item).first()
     if karma:
         return karma.value
Example #6
0
def handle_age(bot, ievent):
    """ age <nick> .. show age of user """
    try:
        who = ievent.args[0].lower()
    except IndexError:
        ievent.missing('<nick>')
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("don't know userhost of %s" % who)
        return
    name = users.getname(userhost)
    if not name:
        ievent.reply("can't find user for %s" % userhost)
        return
    s = create_session()
    bd = s.query(Birthday).filter(Birthday.name==name).first()
    try:
        birthday = bd.birthday
    except (TypeError, AttributeError):
        ievent.reply("can't find birthday data for %s" % who)
        return
    btime = strtotime(birthday)
    if btime == None:
        ievent.reply("can't make a date out of %s" % birthday)
        return
    age = int(time.time()) - int(btime)
    ievent.reply("age of %s is %s" % (who, elapsedstring(age, ywd=True)))
Example #7
0
 def search(self, what):
     """ search quotes """
     s = create_session()
     result = s.query(Quotes).filter(Quotes.quote.like('%%%s%%' %
                                                       what)).all()
     if result:
         return result
Example #8
0
def handle_checkbd(bot, ievent):
    """ bd-check .. check birthdays for current month """
    (nowday, nowmonth) = getdaymonth(time.time())
    mstr = ""
    result = []
    s = create_session()
    bds = s.query(Birthday).all()
    if not bds:
        ievent.reply('no birthdays this month')
        return
    for i in bds:
        btime = strtotime(i.birthday)
        if btime == None:
            continue
        (day, month) = getdaymonth(btime)
        if month == nowmonth:
            result.append((int(day), i.name, i.birthday))
            if day == nowday and month == nowmonth:
                ievent.reply("it's %s's birthday today!" % i.name)
    result.sort(lambda x, y: cmp(x[0], y[0]))
    for i in result:
        mstr += "%s: %s " % (i[1], i[2])
    if mstr:
        mstr = "birthdays this month = " + mstr
        ievent.reply(mstr)
    else:
        ievent.reply('no birthdays this month')
Example #9
0
def handle_checkbd2(bot, ievent):
    """ bd-check <nr> .. show birthdays in month (by number) """
    try:
        monthnr = int(ievent.args[0])
        if monthnr < 1 or monthnr > 12:
            ievent.reply("number must be between 1 and 12")
            return
    except (IndexError, ValueError):
        ievent.missing('<monthnr>')
        return
    mstr = ""
    result = []
    s = create_session()
    bds = s.query(Birthday).all()
    if not bds:
        ievent.reply('no birthdays known')
        return
    for i in bds:
        btime = strtotime(i.birthday)
        if btime == None:
            continue
        (day, month) = getdaymonth(btime)
        if month == bdmonths[monthnr]:
            result.append((int(day), i.name, i.birthday))
    result.sort(lambda x, y: cmp(x[0], y[0]))
    for i in result:
        mstr += "%s: %s " % (i[1], i[2])
    if mstr:
        mstr = "birthdays in %s = " % bdmonths[monthnr] + mstr
        ievent.reply(mstr)
    else:
        ievent.reply('no birthdays found for %s' % bdmonths[monthnr])
Example #10
0
 def search(self, item):
     """ search for matching karma item """
     item = item.lower()
     s = create_session()
     karma = s.query(Karma).filter(Karma.item.like('%%%s%%' % item))
     if karma:
         return karma
Example #11
0
def handle_bd(bot, ievent):
    """ bd [<nr|user>] .. show birthday of month or user """
    if not ievent.rest:    
        handle_checkbd(bot, ievent)
        return
    try:
        int(ievent.args[0])
        handle_checkbd2(bot, ievent)
        return
    except (IndexError, ValueError):
        who = ievent.args[0].lower()
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("don't know userhost of %s" % who)
        return
    name = users.getname(userhost)
    if not name:
        ievent.reply("can't find user for %s" % userhost)
        return
    s = create_session()
    bd = s.query(Birthday).filter(Birthday.name==name).first()
    if bd:
        ievent.reply('birthday of %s is %s' % (who, bd.birthday))
    else:
        ievent.reply('no birthday know for %s' % name)
Example #12
0
 def get(self, name):
     """ get todo list of <name> """
     s = create_session()
     name = name.lower()
     result = s.query(Todo).filter(Todo.name == name).order_by(
         Todo.priority.desc()).all()
     return result
Example #13
0
 def get(self, item):
     """ get karma of item """
     item = item.lower()
     s = create_session()
     karma = s.query(Karma).filter(Karma.item == item).first()
     if karma:
         return karma.value
Example #14
0
 def timetodo(self, name):
     s = create_session()
     name = name.lower()
     if 'mysql' in config['dbtype']:
         items = s.query(Todo).filter(Todo.name==name.lower).filter(Todo.time>0).all()
     else:
         items = s.query(Todo).filter(Todo.name==name.lower).filter(Todo.time>datetime.min).all()
     return items
Example #15
0
 def getwhodown(self, item):
     """ get list of who downed a karma item """
     item = item.lower()
     s = create_session()
     karma = s.query(WhoKarma).filter(WhoKarma.item == item).filter(
         WhoKarma.updown == 'down')
     if karma:
         return [k.nick for k in karma]
Example #16
0
 def whykarmadown(self, item):
     """ get why of karma downs """
     s = create_session()
     item = item.lower()
     karma = s.query(WhyKarma).filter(WhyKarma.item == item).filter(
         WhyKarma.updown == 'down')
     if karma:
         return [k.why for k in karma]
Example #17
0
 def withintime(self, name, time1, time2):
     """ show todo list within time frame """
     name = name.lower()
     s = create_session()
     items = s.query(Todo).filter(
         Todo.name == name.lower
         and Todo.time > datetime.fromtimestamp(time1)
         and Todo.time < datetime.fromtimestamp(time2)).all()
     return items
Example #18
0
 def timetodo(self, name):
     s = create_session()
     name = name.lower()
     if 'mysql' in config['dbtype']:
         items = s.query(Todo).filter(Todo.name == name.lower).filter(
             Todo.time > 0).all()
     else:
         items = s.query(Todo).filter(Todo.name == name.lower).filter(
             Todo.time > datetime.min).all()
     return items
Example #19
0
def handle_bddel(bot, ievent):
    """ bd-del .. delete birthday """
    name = users.getname(ievent.userhost)
    result = 0
    s = create_session()
    bd = s.query(Birthday).filter(Birthday.name==name).first()
    if not bd:
        ievent.reply('no birthday known for %s (%s)' % (ievent.nick, name))
    else:
        s.delete(bd)
        ievent.reply('birthday removed')
Example #20
0
 def whatdown(self, nick):
     """ show what items are upped by nick """
     nick = nick.lower()
     statdict = Statdict()
     s = create_session()
     whokarma = s.query(WhoKarma).filter(WhoKarma.nick==nick).filter(WhoKarma.updown=='down')
     if not whokarma:
         return []
     for i in whokarma:
         statdict.upitem(i.item)
     return statdict.top()
Example #21
0
 def random(self):
     """ get random quote """
     s = create_session()
     result = s.query(Quotes.indx)
     indices = []
     if not result:
         return []
     for i in result:
         indices.append(i[0])
     if indices:
         idnr = random.choice(indices)
         return self.idquote(idnr)
Example #22
0
 def random(self):
     """ get random quote """
     s = create_session()
     result = s.query(Quotes.indx)
     indices = []
     if not result:
         return []
     for i in result:
         indices.append(i[0])
     if indices:
         idnr = random.choice(indices)
         return self.idquote(idnr)
Example #23
0
 def down(self, session, item, reason=None):
     """ lower a karma item with/without reason """
     item = item.lower()
     s = create_session()
     karma = s.query(Karma).filter(Karma.item==item).first()
     if not karma:
         karma = Karma(item, 0)
         session.add(karma)
     karma.value = karma.value - 1
     if reason:
         whykarma = WhyKarma(item, 'down', reason.strip())
         session.save(whykarma)
Example #24
0
 def whatdown(self, nick):
     """ show what items are upped by nick """
     nick = nick.lower()
     statdict = Statdict()
     s = create_session()
     whokarma = s.query(WhoKarma).filter(WhoKarma.nick == nick).filter(
         WhoKarma.updown == 'down')
     if not whokarma:
         return []
     for i in whokarma:
         statdict.upitem(i.item)
     return statdict.top()
Example #25
0
 def good(self, limit=10):
     """ show top 10 of karma items """
     statdict = Statdict()
     s = create_session()
     karma = s.query(Karma).all()
     if not karma:
         return []
     for i in karma:
         if i.item.startswith('quote '):
             continue
         statdict.upitem(i.item, i.value)
     return statdict.top(limit=limit)
Example #26
0
 def good(self, limit=10):
     """ show top 10 of karma items """
     statdict = Statdict()
     s = create_session()
     karma = s.query(Karma).all()
     if not karma:
         return []
     for i in karma:
         if i.item.startswith('quote '):
             continue
         statdict.upitem(i.item, i.value)
     return statdict.top(limit=limit)
Example #27
0
 def down(self, session, item, reason=None):
     """ lower a karma item with/without reason """
     item = item.lower()
     s = create_session()
     karma = s.query(Karma).filter(Karma.item == item).first()
     if not karma:
         karma = Karma(item, 0)
         session.add(karma)
     karma.value = karma.value - 1
     if reason:
         whykarma = WhyKarma(item, 'down', reason.strip())
         session.save(whykarma)
Example #28
0
 def quotebad(self, limit=10):
     """ show lowest 10 of negative karma items """
     statdict = Statdict()
     s = create_session()
     karma = s.query(Karma).all()
     if not karma:
         return []
     for i in karma:
         if not i.item.startswith('quote '):
             continue
         statdict.upitem(i.item, i.value)
     return statdict.down(limit=limit)
Example #29
0
 def quotebad(self, limit=10):
     """ show lowest 10 of negative karma items """
     statdict = Statdict()
     s = create_session()
     karma = s.query(Karma).all()
     if not karma:
         return []
     for i in karma:
         if not i.item.startswith('quote '):
             continue
         statdict.upitem(i.item, i.value)
     return statdict.down(limit=limit)
Example #30
0
def handle_bdset(bot, ievent):
    """ bd-set <date> .. set birthday """
    try:
        what = ievent.args[0]
        if not re.search('\d*\d-\d*\d-\d\d\d\d', what):
            ievent.reply('i need a date in the format day-month-year')
            return
    except IndexError:
        ievent.missing('<date>')
        return
    name = users.getname(ievent.userhost)
    s = create_session()
    s.begin(subtransactions=True)
    bd = s.query(Birthday).filter(Birthday.name==name).first()
    if not bd:
        bd = Birthday(name, what)
        s.save(bd)
    else:
        bd.birthday = what
    s.commit()
    ievent.reply('birthday set')
Example #31
0
 def searchlast(self, what, nr):
     """ search quotes """
     s = create_session()
     result = s.query(Quotes).filter(Quotes.quote.like('%%%s%%' % what)).order_by(Quotes.indx.desc()).limit(nr)
     if result:
         return result
Example #32
0
 def whoquote(self, quotenr):
     """ get who quoted the quote """
     s = create_session()
     quote = s.query(Quotes).filter(Quotes.indx == quotenr).first()
     if quote:
         return quote
Example #33
0
 def last(self, nr=1):
     """ get last quote """
     s = create_session()
     result = s.query(Quotes).order_by(Quotes.indx.desc()).limit(nr)
     if result:
         return result
Example #34
0
 def get(self, item):
     """ get infoitems """
     s = create_session()
     item = item.lower()
     result = [r.description for r in s.query(InfoItems).filter_by(item=item)]
     return result
Example #35
0
 def withintime(self, name, time1, time2):
     """ show todo list within time frame """
     name = name.lower()
     s = create_session()
     items = s.query(Todo).filter(Todo.name==name.lower and Todo.time>datetime.fromtimestamp(time1) and Todo.time<datetime.fromtimestamp(time2)).all()
     return items
Example #36
0
 def toolate(self, name):
     """ show if there are any time related todoos that are too late """
     s = create_session()
     items = s.query(Todo).filter(Todo.name==name.lower and Todo.time<datetime.now()).all()
     return items
Example #37
0
 def getwarnsec(self, todonr):
     """ get priority of todonr """
     s = create_session()
     result =  s.query(Todo).filter(Todo.indx==todonr).first()
     return result
Example #38
0
 def getid(self, idnr):
     """ get todo data of <idnr> """
     s = create_session()
     result = s.query(Todo).filter(Todo.indx==idnr).first()
     return result
Example #39
0
 def get(self, name):
     """ get todo list of <name> """
     s = create_session()
     name = name.lower()
     result = s.query(Todo).filter(Todo.name==name).order_by(Todo.priority.desc()).all()
     return result
Example #40
0
 def size(self):
     """ return number of todo's """
     s = create_session()
     count = s.query(sa.func.count(Todo.indx)).first()[0]
     return count 
Example #41
0
 def size(self):
     """ return number of items """
     s = create_session()
     count = s.query(sa.func.count(Karma.item)).first()[0]
     return count
Example #42
0
 def size(self):
     """ return number of todo's """
     s = create_session()
     count = s.query(sa.func.count(Lists.indx)).count()
     return count 
Example #43
0
 def searchitem(self, search):
     """ search items """
     s = create_session() 
     result = s.query(InfoItems).filter(InfoItems.item.like('%%%s%%' % search))
     return result
Example #44
0
 def size(self):
     """ return number of items """
     s = create_session()
     count = s.query(sa.func.count(InfoItems.indx)).first()[0]
     return count
Example #45
0
def getlists(username):
    """ get all lists of user """
    s = create_session()
    lists = s.query(Lists).filter(Lists.username==username)
    if lists:
        return lists
Example #46
0
 def searchdescr(self, search):
     """ search descriptions """
     s = create_session()
     result = s.query(InfoItems).filter(InfoItems.description.like('%%%s%%' % search))
     return result
Example #47
0
def getlist(username, listname):
    """ get list of user """
    s = create_session()
    lists = s.query(Lists).filter(Lists.username==username).filter(Lists.listname==listname)
    if lists:
        return lists