from line_notify import LineNotify
# class BaseLineModel(object):
#     def __init__(self):
#         self.linebot = LineBot(token)
#         self.linenotify = LineNotify("kwfEg8TIVcGCHJIzhMYTqXL5xE1IkmTSL1xzL7pXAnd")
# class PunchLineModel(BaseLineModel):
#     def Broadcast(self, time, name, temperature, image):
#         time = time.strftime("%H:%M:%S")
#         message = "{0}'s temperature is {1} at {2}".format(name, temperature, time)
#         imageURL = image.split('/')[-1]
#         imageURL = imageURL.split('.')[0]
#         imageURL = "https://api.rd.isrg.tw/images/{0}".format(imageURL)
#         self.linebot.push_message("U2dd5e17cc89d399cb76e9503a8cb5a80", TextSendMessage(text=message))
#         self.linebot.push_message("U2dd5e17cc89d399cb76e9503a8cb5a80", ImageSendMessage(original_content_url=imageURL, preview_image_url=imageURL))
#         # self.linebot.broadcast(TextSendMessage(text=message))
#         # self.linebot.broadcast(ImageSendMessage(original_content_url=imageURL, preview_image_url=imageURL))
#         self.linenotify.send(message, image_path=image)
class BaseLineNotifyModel(object):
    def __init__(self, token="kwfEg8TIVcGCHJIzhMYTqXL5xE1IkmTSL1xzL7pXAnd"):
        self.linenotify = LineNotify(token)
class PunchNotifyModel(BaseLineNotifyModel):
    def Broadcast(self, time, name, temperature, image):
        time = time.strftime("%H:%M:%S")
        # 訪客或溫度異常才顯示
        if temperature > 37.5:
            message = "{0} 於 {1} 打卡，溫度為 {2}，異常!!".format(name, time, temperature)
        elif(name=="unknow"):
            message = "{0} 於 {1} 打卡，測量溫度為 {2}".format(name, time, temperature)
        else:
            return True
        try:
            self.linenotify.send(message, image_path=image)
            # self.linenotify.send(message)
            return True
        except:
            return False
    def BroadcastMsg(self,dt,job,msg):
        dt = dt.strftime("%H:%M:%S")
        # 未出席名單推送
        message = "{}\n{}\n{}".format(dt,job ,msg)
        try:
            self.linenotify.send(message)
            # self.linenotify.send(message)
            return True
        except:
            return False
