Example #1
0
    def notifyTester(self, who, host_url, project_url, branch_name):
        botGerrit = BotGerrit()
        botJira = BotJira()
        today = datetime.date.today()
        yesterday = today - datetime.timedelta(days=1)
        # botPatchs = botGerrit.get_patch_info_from_file(yesterday)
        botPatchs = botGerrit.get_patch_info_from_project(host_url=host_url,
                                                          project_url=project_url,
                                                          branch_name=branch_name,
                                                          status='merged',
                                                          yesterday=yesterday,
                                                          today=today)
        if (len(botPatchs) > 0):
            message = "%s GameDock模块合入%s分支问题数 = %d \n" \
                      "👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 \n" % (yesterday, branch_name, len(botPatchs))

            for botPatch in botPatchs:
                botIssue = botJira.searchIssue(botPatch.issue)
                message += review_message.format(issue=botPatch.issue,
                                                 issue_link=botPatch.issue_link,
                                                 owner=botPatch.owner_name,
                                                 patch_link=botPatch.url,
                                                 title=botIssue.title)

            print(datetime.datetime.now())
            print(message)

            if self.isRaspberryPi:
                ding = DingDing(self.access_token)
                ding.set_secret(self.secret)
                ding.send_text(message)
            else:
                bot = Bot(who)
                bot.set_text(message, type='text').send()
Example #2
0
 def notifyTrack(self, sql, who):
     botIssues = self.fetchIssues(sql)
     for botIssue in botIssues:
         if self.isRaspberryPi:
             message = review_message_pi.format(botIssue.issue,
                                                botIssue.link)
             ding = DingDing(self.access_token)
             ding.set_secret(self.secret)
             ding.send_markdown('处理问题提醒', message)
         else:
             message = review_message.format(botIssue.issue, botIssue.link)
             bot = Bot(who)
             bot.set_text(message, type='markdown').send()
Example #3
0
 def notify(self, who, sql):
     botIssues = self.fetchIssues(sql)
     message = self.parseIssues(botIssues)
     print("\n")
     if self.isRaspberryPi:
         ding = DingDing(self.access_token)
         ding.set_secret(self.secret)
         ding.send_markdown('DI统计', message)
     else:
         if who == "":
             who = self.bot_key_test
         bot = Bot(who)
         bot.set_text(message, type='markdown').send()
Example #4
0
    def notifyReview(self, who, sql):
        self.fetchGameDockPatchMessage(who)
        self.fetchGameDockEnginePatchMessage(who)
        botIssues = self.fetchIssues(sql)
        for botIssue in botIssues:
            if "" != botIssue.comment:
                flags = False
                result = self.tableIssue.find_one(issue=botIssue.issue)
                print(datetime.datetime.now())
                if result is not None:
                    if result["dock_team"] == 1:
                        print("dock team %s has been saved\n" %
                              (botIssue.issue))
                    else:
                        flags = True
                        self.tableIssue.update(
                            dict(issue=botIssue.issue,
                                 dock_team=1,
                                 game_team=result["game_team"]), ["issue"])
                        print("dock team %s need save(update)\n" %
                              (botIssue.issue))
                else:
                    flags = True
                    self.tableIssue.insert(
                        dict(issue=botIssue.issue, dock_team=1, game_team=0))
                    print("dock team %s need save\n" % (botIssue.issue))

                if (flags):
                    if self.isRaspberryPi:
                        message_format = review_message_pi
                    else:
                        message_format = review_message

                    message = message_format.format(botIssue.issue,
                                                    botIssue.link,
                                                    botIssue.commentAuthor,
                                                    botIssue.comment, "")
                    print(message)
                    if self.isRaspberryPi:
                        ding = DingDing(self.access_token)
                        ding.set_secret(self.secret)
                        ding.send_markdown('Code review', message)
                    else:
                        if who == "":
                            who = self.bot_key_test
                        bot = Bot(who)
                        bot.set_text(message, type='markdown').send()
                        bot.set_text('', type='text').set_mentioned_list(
                            ["@all"]).send()
Example #5
0
def jobFetch():
    ethusdt_url = url.format(who='ethusdt')
    ethusdt = requests.post(ethusdt_url)
    eth = ethusdt.json()['data'][0]['close']
    print(eth)
    btcusdt_url = url.format(who='btcusdt')
    btcusdt = requests.post(btcusdt_url)
    btc = btcusdt.json()['data'][0]['close']
    print(btc)

    ding = DingDing(access_token)
    ding.set_secret(secret)
    ding.send_markdown(
        'BTC和ETH',
        message.format(eth_url=ethusdt_url,
                       eth_price=eth,
                       btc_url=btcusdt_url,
                       btc_price=btc))
Example #6
0
    def notifyMergeCode(self, who, sql, force):
        botIssues = self.fetchIssues(sql)
        datas = dict()
        issue_count = 0
        total_comment_message = ""
        total_author_message = ""

        if force:
            flags = False
        else:
            flags = True

        for botIssue in botIssues:
            if "" != botIssue.comment:
                if (flags):
                    result = self.tableIssue.find_one(issue=botIssue.issue)
                    print(datetime.datetime.now())
                    if result is not None:
                        if result["game_team"] == 1:
                            print("game team %s has been saved\n" %
                                  (botIssue.issue))
                        else:
                            flags = False
                            self.tableIssue.update(
                                dict(issue=botIssue.issue,
                                     dock_team=result["dock_team"],
                                     game_team=1), ["issue"])
                            print("game team %s need save(update)\n" %
                                  (botIssue.issue))
                    else:
                        flags = False
                        self.tableIssue.insert(
                            dict(issue=botIssue.issue,
                                 dock_team=0,
                                 game_team=1))
                        print("game team %s need save\n" % (botIssue.issue))

                if botIssue.commentAuthor not in datas:
                    datas[botIssue.commentAuthor] = [0]

                datas[botIssue.commentAuthor][0] += 1
                issue_count += 1

                total_comment_message = total_comment_message + comment_message.format(
                    count=str(issue_count),
                    who=botIssue.commentAuthor,
                    comment=botIssue.comment)
        for key, values in datas.items():
            # print("key = %s , values = %s" % (key, values))
            count = str(values)
            total_author_message = total_author_message + author_message.format(
                who=key, count=count)

        total_message = time_message.format(
            time=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
            count=str(issue_count
                      )) + total_comment_message + total_message_count.format(
                          count=str(issue_count)) + total_author_message

        if flags:
            print(datetime.datetime.now())
            print("game team has been notify\n")
        else:
            print(total_message)
            if issue_count > 0:
                if self.isRaspberryPi:
                    ding = DingDing(self.access_token)
                    ding.set_secret(self.secret)
                    ding.send_text(total_message)
                else:
                    if who == "":
                        who = self.bot_key_test
                    bot = Bot(who)
                    bot.set_text(total_message, type='text').send()
Example #7
0
if __name__ == '__main__':
    try:
        result = os.popen("iwgetid -r").readlines()[0].strip()
        print(result)
        if 'bskj-sh' == result:
            print("has connected bskj-sh wifi, need login user account")
            data = dict()
            data['opr'] = 'pwdLogin'
            data['rememberPwd'] = 1
            data['userName'] = user
            data['pwd'] = pwd
            r = requests.post(url, data)
            # r = requests.post(url, body)
            time.sleep(2)
    except:
        pass

    process = os.popen("hostname -I")
    outputs = process.readlines()
    for output in outputs:
        ip = output.strip()
        break

    print(ip)
    send_message = message.format(ip=ip, ad=ip)
    process.close()

    ding = DingDing(access_token)
    ding.set_secret(secret)
    ding.send_text(send_message)
Example #8
0
    def fetchGameDockPatchMessage(self, who):
        botGerrit = BotGerrit()
        botJira = BotJira()

        botPatchs = botGerrit.get_comment_patch_info_from_project(
            host_url=self.host_url_prv,
            project_url=self.project_url_game_dock,
            status='open',
            comment='need_review')
        for botPatch in botPatchs:
            flags = False
            result = self.tableIssue.find_one(issue=botPatch.number)
            print(datetime.datetime.now())
            if result is not None:
                if result["dock_team"] == 1:
                    print("dock team %s has been saved\n" % (botPatch.number))
                else:
                    flags = True
                    self.tableIssue.update(
                        dict(issue=botPatch.number,
                             dock_team=1,
                             game_team=result["game_team"]), ["issue"])
                    print("dock team %s need save(update)\n" %
                          (botPatch.number))
            else:
                flags = True
                self.tableIssue.insert(
                    dict(issue=botPatch.number, dock_team=1, game_team=0))
                print("dock team %s need save\n" % (botPatch.number))

            if (flags):
                if self.isRaspberryPi:
                    message_format = review_message_pi
                else:
                    message_format = review_message

                issue = "Patch未填单号"
                link = "botPatch.url"

                if botPatch.issue != "null":
                    botIssue = botJira.searchIssue(botPatch.issue)
                    if botIssue is not None:
                        issue = botIssue.issue
                        link = botIssue.link

                message = message_format.format(issue, link,
                                                botPatch.owner_name,
                                                botPatch.url,
                                                botPatch.commitMessage)
                print(message)
                if self.isRaspberryPi:
                    ding = DingDing(self.access_token)
                    ding.set_secret(self.secret)
                    ding.send_markdown('Code review', message)
                else:
                    if who == "":
                        who = self.bot_key_test
                    bot = Bot(who)
                    bot.set_text(message, type='markdown').send()
                    bot.set_text('',
                                 type='text').set_mentioned_list(["@all"
                                                                  ]).send()