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]
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
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]
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
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
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)))
def search(self, what): """ search quotes """ s = create_session() result = s.query(Quotes).filter(Quotes.quote.like('%%%s%%' % what)).all() if result: return result
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')
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])
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)
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
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
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
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]
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]
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
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
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')
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()
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)
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)
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()
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)
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)
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)
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')
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
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
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
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
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
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
def getwarnsec(self, todonr): """ get priority of todonr """ s = create_session() result = s.query(Todo).filter(Todo.indx==todonr).first() return result
def getid(self, idnr): """ get todo data of <idnr> """ s = create_session() result = s.query(Todo).filter(Todo.indx==idnr).first() return result
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
def size(self): """ return number of todo's """ s = create_session() count = s.query(sa.func.count(Todo.indx)).first()[0] return count
def size(self): """ return number of items """ s = create_session() count = s.query(sa.func.count(Karma.item)).first()[0] return count
def size(self): """ return number of todo's """ s = create_session() count = s.query(sa.func.count(Lists.indx)).count() return count
def searchitem(self, search): """ search items """ s = create_session() result = s.query(InfoItems).filter(InfoItems.item.like('%%%s%%' % search)) return result
def size(self): """ return number of items """ s = create_session() count = s.query(sa.func.count(InfoItems.indx)).first()[0] return count
def getlists(username): """ get all lists of user """ s = create_session() lists = s.query(Lists).filter(Lists.username==username) if lists: return lists
def searchdescr(self, search): """ search descriptions """ s = create_session() result = s.query(InfoItems).filter(InfoItems.description.like('%%%s%%' % search)) return result
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