Example #1
0
 def __notice_notdone(self):
     self.now = dt.datetime.now()
     db = DB(os.environ['TODO_DB'])
     self.dict_list = db.dict_list()
     self.channel = os.environ['SLACK_CHANNEL']
     for dict in self.dict_list:
         # 前バージョンとの互換性を保つ
         if not "noticetime" in dict.keys():
             continue
         noticetime = int(dict['noticetime'])
         try:
             self.__limit_at = dt.datetime.strptime(dict["limit_at"],
                                                    '%Y/%m/%d %H:%M')
             # statusの更新
             if self.now > self.__limit_at and dict['status'] == '未':
                 db.change_id(dict['id'], 'status', '期限切れ')
         except:
             break
         color = ''
         text = ''
         post = False
         if dict["status"] == '未':
             if self.__limit_at < self.now + dt.timedelta(
                     hours=1) and noticetime == 1:
                 text = "期限まであと1時間。ひょっとして提出し忘れてるんじゃ?:face_with_rolling_eyes::face_with_rolling_eyes:"
                 noticetime = 0
                 color = 'ff4500'
                 post = True
             elif self.__limit_at < self.now + dt.timedelta(
                     days=1) and noticetime == 2:
                 text = "期限まであと1日もありません!!のんびりしてる暇なんてありませんね:sweat_drops:"
                 noticetime = 1
                 color = 'ffff00'
                 post = True
             elif self.__limit_at < self.now + dt.timedelta(
                     days=3) and noticetime == 3:
                 text = "期限まであと3日。そろそろとりかかろう...:sunglasses:"
                 noticetime = 2
                 color = '7cfc00'
                 post = True
         if post == True:
             attachments = [{
                 "color":
                 color,
                 "blocks": [{
                     "type": "section",
                     "text": {
                         "type":
                         "mrkdwn",
                         "text":
                         '*' + dict["title"] + '*\n' + '期限:' +
                         dict["limit_at"] + '\nid:' + dict["id"]
                     }
                 }]
             }]
             tools.postMessage(text,
                               attachments,
                               channel=self.channel,
                               icon_emoji=":panda_face:")
             db.change_id(dict['id'], 'noticetime', noticetime)
Example #2
0
    def __notice_notdone(self):
        self.now = dt.datetime.now()
        db = DB(os.environ['TODO_DB'])
        self.dict_list = db.dict_list()
        self.channel = os.environ['SLACK_CHANNEL']
        self.notice_tasks = []
        for dict in self.dict_list:
            # 前バージョンとの互換性を保つ
            if not "noticetime" in dict.keys():
                continue
            noticetime = int(dict['noticetime'])
            try:
                self.__limit_at = dt.datetime.strptime(dict["limit_at"],
                                                       '%Y/%m/%d %H:%M')
                # statusの更新
                if self.now > self.__limit_at and dict['status'] == '未':
                    db.change_id(dict['id'], 'status', '期限切れ')
            except:
                break
            color = ''
            text = ''
            post_dm = False
            post_announce = False
            attachments = []
            # 全体アナウンス
            if dict['user'] == 'all':
                if self.__limit_at < self.now + dt.timedelta(
                        hours=1) and noticetime == 1:
                    text = '3日後の予定をお知らせします。'
                    noticetime = 0
                    color = 'ff4500'
                    post_announce = True
                elif self.__limit_at < self.now + dt.timedelta(
                        days=1) and noticetime == 2:
                    text = '1日後の予定をお知らせします。'
                    noticetime = 1
                    color = 'ffff00'
                    post_announce = True
                elif self.__limit_at < self.now + dt.timedelta(
                        days=3) and noticetime == 3:
                    text = '1時間後の予定をお知らせします。'
                    noticetime = 2
                    color = '7cfc00'
                    post_announce = True
            else:
                if dict["status"] == '未':
                    if self.__limit_at < self.now + dt.timedelta(
                            hours=1) and noticetime == 1:
                        text = "期限まであと1時間。ひょっとして提出し忘れてるんじゃ?:face_with_rolling_eyes::face_with_rolling_eyes:"
                        noticetime = 0
                        color = 'ff4500'
                        post_dm = True
                    elif self.__limit_at < self.now + dt.timedelta(
                            days=1) and noticetime == 2:
                        text = "期限まであと1日もありません!!のんびりしてる暇なんてありませんね:sweat_drops:"
                        noticetime = 1
                        color = 'ffff00'
                        post_dm = True
                    elif self.__limit_at < self.now + dt.timedelta(
                            days=3) and noticetime == 3:
                        text = "期限まであと3日。そろそろとりかかろう...:sunglasses:"
                        noticetime = 2
                        color = '7cfc00'
                        post_dm = True
            if post_dm == True:
                dict["limit_at"] = dict["limit_at"][5:]
                if dict["subject"] != 'None' and dict["note"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                ' *' + dict["title"] + '* \n教科:' +
                                dict["subject"] + '\n期限:' + dict["limit_at"] +
                                '\n id : `' + str(dict["id"]) + '`'
                            }
                        }, {
                            "type":
                            "context",
                            "elements": [{
                                "type": "plain_text",
                                "text": "※備考\n" + dict["note"]
                            }]
                        }]
                    }]
                elif dict["subject"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                ' *' + dict["title"] + '* \n教科:' +
                                dict["subject"] + '\n期限:' + dict["limit_at"] +
                                '\n id : `' + str(dict["id"]) + '` '
                            }
                        }]
                    }]
                elif dict["note"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                ' *' + dict["title"] + '* \n期限:' +
                                dict["limit_at"] + '\n id : `' +
                                str(dict["id"]) + '` '
                            }
                        }, {
                            "type":
                            "context",
                            "elements": [{
                                "type": "plain_text",
                                "text": "※備考\n" + dict["note"]
                            }]
                        }]
                    }]
                else:
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                ' *' + dict["title"] + '* \n期限:' +
                                dict["limit_at"] + '\n id : `' +
                                str(dict["id"]) + '` '
                            }
                        }]
                    }]

            if post_announce == True:
                dict["user"] = self.channel
                dict["limit_at"] = dict["limit_at"][5:]
                if dict["subject"] != 'None' and dict["note"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                '*' + dict["title"] + '* の情報です。\n教科:' +
                                dict["subject"] + '\n日付:' + dict["limit_at"]
                            }
                        }, {
                            "type":
                            "context",
                            "elements": [{
                                "type": "plain_text",
                                "text": "※備考\n" + dict["note"]
                            }]
                        }]
                    }]
                elif dict["subject"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                '*' + dict["title"] + '* の情報です。\n教科:' +
                                dict["subject"] + '\n日付:' + dict["limit_at"]
                            }
                        }]
                    }]
                elif dict["note"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                '*' + dict["title"] + '* の情報です\n日付:' +
                                dict["limit_at"]
                            }
                        }, {
                            "type":
                            "context",
                            "elements": [{
                                "type": "plain_text",
                                "text": "※備考\n" + dict["note"]
                            }]
                        }]
                    }]
                else:
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                '*' + dict["title"] + '* の情報です\n日付:' +
                                dict["limit_at"]
                            }
                        }]
                    }]

            if post_announce or post_dm:
                # tools.postMessage(text, attachments, channel=dict['user'], icon_emoji=":panda_face:")
                db.change_id(dict['id'], 'noticetime', noticetime)
                self.notice_tasks.append({
                    "text": text,
                    "attachments": attachments,
                    "channel": dict["user"]
                })

        return self.notice_tasks