Exemplo n.º 1
0
 def test_summary(self):
     data = {
             "Color": "RED",
             "Total": "90"
             }
     attachments = MsgTemplate.make_summary_template(data)
     self.assertEqual(isinstance(attachments, list), True)
Exemplo n.º 2
0
 def test_air_quality(self):
     data = {
         "cai": {
             "grade": "1",
             "value": "good",
             "description": "좋음"
             },
         "pm25": {}
     }
     attachments = MsgTemplate.make_air_quality_template("station_name", data)
     self.assertEqual(isinstance(attachments, list), True)
Exemplo n.º 3
0
 def test_weather(self):
     attachments = MsgTemplate.make_weather_template("address", "icon", "summary", "temperature")
     self.assertEqual(isinstance(attachments, list), True)
Exemplo n.º 4
0
 def test_giphy(self):
     attachments = MsgTemplate.make_giphy_template("query", "url")
     self.assertEqual(isinstance(attachments, list), True)
Exemplo n.º 5
0
 def test_help(self):
     attachments = MsgTemplate.make_help_template("guide", {})
     self.assertEqual(isinstance(attachments, list), True)
Exemplo n.º 6
0
 def test_skill(self):
     attachments = MsgTemplate.make_skill_template("pretext", {})
     self.assertEqual(isinstance(attachments, list), True)
Exemplo n.º 7
0
    def total_score(self):
        today_data = self.__get_total_score()
        self.data_handler.edit_summary(today_data)

        color = MsgResource.SCORE_COLOR(today_data["total"])
        today_data["Color"] = color

        yesterday_data = self.__get_total_score(-1)
        for k, v in today_data.items():
            if isinstance(v, float):
                y_point = yesterday_data.get(k, False)
                if not y_point:
                    continue
                else:
                    diff = v - float(y_point)
                    diff = round(diff * 100) / 100

                if diff > 0:
                    diff = "+" + str(diff)
                else:
                    diff = str(diff)
                today_data[k] = str(v) + " (" + diff + ")"
            elif isinstance(v, bool):
                if v:
                    today_data[k] = "O"
                else:
                    today_data[k] = "X"

        record = self.data_handler.read_record()
        activity = record.get("activity", {})

        # Sleep Time
        go_to_bed = activity.get("go_to_bed", None)
        wake_up = activity.get("wake_up", None)

        if go_to_bed is not None and wake_up is not None:
            go_to_bed_time = arrow.get(go_to_bed)
            wake_up_time = arrow.get(wake_up)

            sleep_hour = ArrowUtil.get_curr_time_diff(start=go_to_bed_time,
                                                      stop=wake_up_time,
                                                      base_hour=True)
            today_data["Sleep"] = (go_to_bed_time.format("HH:mm") + " ~ " +
                                   wake_up_time.format("HH:mm") + " : " +
                                   str(sleep_hour) + "h (" +
                                   str(today_data["Sleep"]) + ")")

        # Working Hour
        in_company = activity.get("in_company", None)
        out_company = activity.get("out_company", None)

        if in_company is not None and out_company is not None:
            in_company_time = arrow.get(in_company)
            out_company_time = arrow.get(out_company)

            working_hour = ArrowUtil.get_curr_time_diff(start=in_company_time,
                                                        stop=out_company_time,
                                                        base_hour=True)
            today_data["Working Hour"] = (in_company_time.format("HH:mm") +
                                          " ~ " +
                                          out_company_time.format("HH:mm") +
                                          " : " + str(working_hour) + "h")

        attachments = MsgTemplate.make_summary_template(today_data)
        self.slackbot.send_message(attachments=attachments)
Exemplo n.º 8
0
 def test_bus(self):
     attachments = MsgTemplate.make_bus_stop_template({})
     self.assertEqual(isinstance(attachments, list), True)
 def test_feed(self):
     attachments = MsgTemplate.make_feed_template(("title", "link", "description"))
     self.assertEqual(isinstance(attachments, list), True)
 def test_todoist(self):
     attachments = MsgTemplate.make_todoist_task_template([])
     self.assertEqual(isinstance(attachments, list), True)
 def test_air_quality(self):
     data = {"cai": {"grade": "1", "value": "good", "description": "좋음"}, "pm25": {}}
     attachments = MsgTemplate.make_air_quality_template("station_name", data)
     self.assertEqual(isinstance(attachments, list), True)
 def test_weather(self):
     attachments = MsgTemplate.make_weather_template(
         "address", "icon", "summary", "temperature"
     )
     self.assertEqual(isinstance(attachments, list), True)
 def test_giphy(self):
     attachments = MsgTemplate.make_giphy_template("query", "url")
     self.assertEqual(isinstance(attachments, list), True)
 def test_help(self):
     attachments = MsgTemplate.make_help_template("guide", {})
     self.assertEqual(isinstance(attachments, list), True)
 def test_skill(self):
     attachments = MsgTemplate.make_skill_template("pretext", {})
     self.assertEqual(isinstance(attachments, list), True)
Exemplo n.º 16
0
 def test_todoist(self):
     attachments = MsgTemplate.make_todoist_task_template([])
     self.assertEqual(isinstance(attachments, list), True)
Exemplo n.º 17
0
 def test_feed(self):
     attachments = MsgTemplate.make_feed_template(("title", "link", "description"))
     self.assertEqual(isinstance(attachments, list), True)
 def test_bus(self):
     attachments = MsgTemplate.make_bus_stop_template({})
     self.assertEqual(isinstance(attachments, list), True)
 def test_summary(self):
     data = {"Color": "RED", "total": "90"}
     attachments = MsgTemplate.make_summary_template(data)
     self.assertEqual(isinstance(attachments, list), True)
Exemplo n.º 20
0
    def total_score(self):
        today_data = self.__get_total_score()
        self.data_handler.edit_summary(today_data)

        color = MsgResource.SCORE_COLOR(today_data["total"])
        today_data["Color"] = color

        yesterday_data = self.__get_total_score(-1)
        for k, v in today_data.items():
            if isinstance(v, float):
                y_point = yesterday_data.get(k, False)
                if not y_point:
                    continue
                else:
                    diff = v - float(y_point)
                    diff = round(diff * 100) / 100

                if diff > 0:
                    diff = "+" + str(diff)
                else:
                    diff = str(diff)
                today_data[k] = str(v) + " (" + diff + ")"
            elif isinstance(v, bool):
                if v:
                    today_data[k] = "O"
                else:
                    today_data[k] = "X"

        record = self.data_handler.read_record()
        activity = record.get("activity", {})

        # Sleep Time
        go_to_bed = activity.get("go_to_bed", None)
        wake_up = activity.get("wake_up", None)

        if go_to_bed is not None and wake_up is not None:
            go_to_bed_time = arrow.get(go_to_bed)
            wake_up_time = arrow.get(wake_up)

            sleep_hour = ArrowUtil.get_curr_time_diff(
                start=go_to_bed_time, stop=wake_up_time, base_hour=True
            )
            today_data["Sleep"] = (
                go_to_bed_time.format("HH:mm")
                + " ~ "
                + wake_up_time.format("HH:mm")
                + " : "
                + str(sleep_hour)
                + "h ("
                + str(today_data["Sleep"])
                + ")"
            )

        # Working Hour
        in_company = activity.get("in_company", None)
        out_company = activity.get("out_company", None)

        if in_company is not None and out_company is not None:
            in_company_time = arrow.get(in_company)
            out_company_time = arrow.get(out_company)

            working_hour = ArrowUtil.get_curr_time_diff(
                start=in_company_time, stop=out_company_time, base_hour=True
            )
            today_data["Working Hour"] = (
                in_company_time.format("HH:mm")
                + " ~ "
                + out_company_time.format("HH:mm")
                + " : "
                + str(working_hour)
                + "h"
            )

        attachments = MsgTemplate.make_summary_template(today_data)
        self.slackbot.send_message(attachments=attachments)