開機或登入時自動傳Line訊息給我,如果有異常的時間點就表示有人偷開你的電腦了! ψ(`∇´)ψ
.py 轉成 .exe 檔
.exe 檔

import datetime
import requests
import os
if __name__ == '__main__':
    # 取得現在時刻
    now = datetime.datetime.now()
    now_str = now.strftime("%Y-%m-%d, %H:%M:%S")
    # print(now_str)
    try:    # 如果有連網路則成功傳送
        if not os.path.exists("buffer.txt"):    # 如果沒有buffer.txt
            with open("buffer.txt", "w") as f:  # 建立新的
                pass
        with open("buffer.txt", "r") as file:   # 讀取buffer.txt
            buffer = file.read()
        # 建立訊息
        message = "\n" + buffer
        message += f"{now_str} [Successed]\n你的筆電在這些時段被登入了\n如果不是本人請多加留意!"
        params = {"message": message}
        # 權杖
        headers = {
            "Authorization": "Bearer " + "your token",
        }
        # 傳送Line notify
        r = requests.post("https://notify-api.line.me/api/notify",
                          headers=headers, params=params)
        # 傳送成功
        with open("buffer.txt", "w") as f:  # 清空buffer.txt
            pass
        with open("log.txt", "a") as file:
            file.write(f"{now_str} [Successed]\n")  # 記在log.txt中
    except Exception as e:  # 沒連網路會跑出錯誤
        with open("buffer.txt", "a") as file:
            file.write(f"{now_str} [Failed]\n")  # 記在buffer.txt中
        with open("log.txt", "a") as file:
            file.write(f"{now_str} [Failed]\n" + f"{e}\n")  # 記在log.txt中
這樣該台電腦line就不能登出囉?
不影響,我是用line notify來通知,只要token沒過期都可以傳訊息