コード例 #1
0
 def send_report(self, uid, ur, previous, send=True, override_uid=None):
     ur = copy.deepcopy(ur)
     previous = copy.deepcopy(previous)
     enricher.Enricher(fake=self.fake).user_enrich(ur, uid)
     enricher.Enricher(fake=self.fake).user_enrich(previous, uid)
     us = ur['user_stats'].get(uid, {})
     pus = previous['user_stats'].get(uid, {})
     blocks = self.make_report(ur, us, previous, pus, uid)
     if not send:
         print("Saving report to slack.json")
         f = open("slack.json", "w")
         f.write(json.dumps(blocks, indent=4))
         f.close()
         return
     # If set to true, this message will be sent as the user who owns the token we use
     as_user = False
     if override_uid:
         uid = override_uid
     for blockset in utils.chunks(blocks, 49):
         if send:
             print("Sending report to {}".format(uid))
             try:
                 response = self.client.chat_postMessage(channel=uid,
                                                         blocks=blockset,
                                                         parse='full',
                                                         as_user=as_user,
                                                         unfurl_links=True,
                                                         link_names=True)
                 # print("Response: {}".format(response))
             except Exception:
                 print(Exception)
                 print(json.dumps(blockset, indent=4))
                 sys.exit(0)
コード例 #2
0
 def send_report(self,
                 cid,
                 ur,
                 previous,
                 send=True,
                 override_uid=None,
                 summary=False):
     enricher.Enricher(fake=self.fake).enrich(ur)
     enricher.Enricher(fake=self.fake).enrich(previous)
     blocks = self.make_report(ur, previous, cid)
     if not send:
         print("Saving report to slack.json")
         f = open("slack.json", "w")
         f.write(json.dumps(blocks, indent=4))
         f.close()
         return
     # If set to true, this message will be sent as the user who owns the token we use
     as_user = False
     if override_uid:
         cid = override_uid
     urls = []
     for blockset in utils.chunks(blocks, 49):
         if send:
             print("Sending report to {}".format(cid))
             try:
                 response = self.client.chat_postMessage(channel=cid,
                                                         blocks=blockset,
                                                         parse='full',
                                                         as_user=as_user,
                                                         unfurl_links=True,
                                                         link_names=True)
                 # print("Response: {}".format(response))
                 urls.append(
                     utils.make_url(response['channel'], response['ts']))
             except Exception:
                 print(Exception)
                 print(json.dumps(blockset, indent=4))
                 sys.exit(0)
     if summary and urls:
         cid = self.channel.get(config.channel_stats)['slack_cid']
         self.client.chat_postMessage(channel=cid,
                                      parse='full',
                                      as_user=as_user,
                                      unfurl_links=True,
                                      link_names=True,
                                      text=urls[0])
コード例 #3
0
 def __init__(self, fake=False):
     self.fake = fake
     self.jinja_environment = jinja2.Environment(
         loader=jinja2.FileSystemLoader("."))
     self.general_template = self.jinja_environment.get_template(
         "templates/general.html")
     self.user_template = self.jinja_environment.get_template(
         "templates/user.html")
     self.enricher = enricher.Enricher(fake=fake)
コード例 #4
0
 def __init__(self, fake=False):
     random.seed(time.time())
     self.fake = fake
     self.channel = channel.Channel()
     self.fake_channel = channel.Channel(fake=True)
     if self.fake:
         self.channel = self.fake_channel
     self.rn = random_name.RandomName()
     self.user = user.User(fake=fake)
     self.client = slack.WebClient(token=slack_token.token)
     self.enricher = enricher.Enricher(fake=fake)
コード例 #5
0
 def __init__(self, fake=False):
     self.sf = slack_formatter.SlackFormatter()
     random.seed(time.time())
     self.fake = fake
     self.fake_channel = channel.Channel(fake=True)
     self.channel = channel.Channel(fake=fake)
     self.rn = random_name.RandomName()
     self.user = user.User(fake=fake)
     self.client = slack.WebClient(token=slack_token.token)
     self.enricher = enricher.Enricher(fake=fake)
     self.cml = channel_members_log.ChannelMembersLog()
コード例 #6
0
 def __init__(self, fake=False):
     self.sf = slack_formatter.SlackFormatter(fake=fake)
     random.seed(time.time())
     self.fake = fake
     self.fake_channel = channel.Channel(fake=True)
     self.fp = firstpost.FirstPost()
     self.channel = channel.Channel()
     self.rn = random_name.RandomName()
     self.user = user.User(fake=fake)
     self.client = slack.WebClient(token=slack_token.token)
     self.enricher = enricher.Enricher(fake=fake)
     self.uc = user_created.UserCreated()
コード例 #7
0
ファイル: slack_formatter.py プロジェクト: ax42/channelstats
 def __init__(self):
     self.client = slack.WebClient(token=slack_token.token)
     self.enricher = enricher.Enricher()