1 # -*- coding: utf-8 -*-
2 """Get data from database and publish them."""
4 from random import randint
5 from requests import post
6 from cbconf import Conf
10 """This class connects configuration, database access and publishing."""
13 self.db = Db(self.cfg.getCoffeeDbPath())
23 def sendMsgToSlack(self):
24 """Send message to Slack Bot."""
25 return post(self.cfg.getCoffeebotURL(), dumps({"text": self.msg}))
27 def getHeroComment(self):
28 """Return comment for hero."""
32 " because couldn't resist",
36 " - superultramaxidrinker",
37 " and didn't sleep last week",
38 " in last 604800 seconds",
40 " and still drinking",
42 ri = randint(0, len(hsuff) - 1)
45 def getSomeSmile(self):
46 """Return some Slack smile."""
56 ri = randint(0, len(smiles) - 1)
59 def computeEqualDrinkers(self):
60 """Compute equally drunken drinkers."""
61 lc = self.top[0][1] + 1
62 for (un, c) in self.top:
66 self.topeq[-1].append((un, c))
69 def loadTopMateDrinkers(self):
70 """Get list of top Mate drinkers, update message."""
71 self.msg = "*Top 5 Club-Mate drinkers*\n"
72 self.top = self.db.getTopMateDrinkers()
73 totl = [c for (un, c) in self.top]
75 isuff = {1: "st", 2: "nd", 3: "rd", 4: "th", 5: "th"}
77 for (un, c) in self.top[:5]:
78 self.msg += "{}{} is *{}* who drank `{:.2f}` liters".format(
84 self.msg += self.getHeroComment()
88 self.msg += "Oh, and together we drank *{:.2f}* liters {}".format(